Official

A - Nine or Nein Editorial by en_translator


For beginners

Maintain a Boolean variable \(\mathrm{hasnine}\) that manages whether any condition is satisfied, initialized with “false.”

Check each of the four condition; if it is satisfied, set \(\mathrm{hasnine}\) to “true.” Once the four condition is satisfied, use the value of \(\mathrm{hasnine}\) to determine the answer.

Sample code (Python 3)

a, b = map(int, input().split())

hasnine = False
if (a + b == 9):
  hasnine = True
if (a - b == 9):
  hasnine = True
if (a * b == 9):
  hasnine = True
if (a == b * 9):
  hasnine = True

if hasnine:
  print("Nine")
else:
  print("Nein")

Sample code (C++)

#include <iostream>
using std::cin;
using std::cout;


int main (void) {
	int a, b;

	// Input
	cin >> a >> b;

	// Solve
	bool hasnine = false;
	if (a + b == 9) hasnine = true;
	if (a - b == 9) hasnine = true;
	if (a * b == 9) hasnine = true;
	if (a == b * 9) hasnine = true;

	// Output
	if (hasnine) {
		cout << "Nine" << "\n";
	} else {
		cout << "Nein" << "\n";
	}


	return 0;
}