公式
A - Thermometer 解説 by en_translator
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.
This problem asks to receive decimal input and use an if
statement.
One can receive a decimal number in a standard way of your language, such as the double
type in C++ or float
type in Python.
For the received value \(X\), use an if
statement to check if:
- it is greater than or equal to \(38.0\) \({}^\circ\)C,
- it is greater than or equal to \(37.5\) \({}^\circ\)C but less than \(38.0\) \({}^\circ\)C, and
- it is less than \(37.5\) \({}^\circ\)C,
and print the corresponding integer.
Alternatively, one can receive the input not as a decimal number but as a string, split it into the integer and fractional parts, and use an if
statement to compare them.
Sample code (C++)
#include <bits/stdc++.h>
using namespace std;
int main() {
double t;
cin >> t;
if (38.0 <= t) {
cout << 1 << endl;
}
else if (37.5 <= t && t < 38.0) {
cout << 2 << endl;
}
else {
cout << 3 << endl;
}
}
Sample code (Python)
t = float(input())
if 38.0 <= t:
print(1)
elif 37.5 <= t < 38.0:
print(2)
else:
print(3)
Sample code (alternative solution, C++)
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
char c;
cin >> a >> c >> b;
if (38 <= a) {
cout << 1 << endl;
}
else if (a == 37 && 5 <= b) {
cout << 2 << endl;
}
else {
cout << 3 << endl;
}
}
投稿日時:
最終更新: