Official
A - Nine or Nein Editorial by en_translator Editorial for printing
For beginners
- If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
- Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
- 「Python入門 AtCoder Programming Guide for beginners (APG4bPython)」 is a Python tutorial for competitive programmers. Again, this is only in Japanese.
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;
}
posted:
last update: