A - Armor 解説 by en_translator
If you have no idea, start with Problem A - Welcome to AtCoder in practice contest, where you can find basic input/output sample code. We also recommend AtCoder Beginners Selection.
To solve this problem, the following four operations are required:
- Receive \(A\) and \(D\).
- Compare \(A\) and \(B\).
- Branch the program depending on the result of comparison.
- Print the string
YesorNo.
1. Input
We can reuse the sample code in Welcome to AtCoder. For example, if you use Python, the page contains the following code as “Example of Python”:
# -*- coding: utf-8 -*-
# get a integer
a = int(raw_input())
# get two integers separated with half-width break
b, c = map(int, raw_input().split())
# get a string
s = raw_input()
# output
print str(a+b+c) + " " + s
We can use line 5 as follows:
A, D = map(int, input().split())
2. Comparison
Most languages have <= operator. “\(A\) is less than or equal to \(D\)” can be written as A <= D.
3. Conditional branch
Most languages have an if statement or a conditional operator (ternary operator); use either of them with 2. The actual syntax varies depending on your language; use your favorite search engine with “[language] if” (replace “[replace]” with your language).
4. Output
Again, we can reuse the code from Welcome to AtCoder. For example, in case of Python, we can use line 9: replace "{} {}".format(a+b+c, s) with "Yes" and you can print Yes. Same should apply to most of the other languages too. (In AtCoder, the output checker is case-sensitive by default.)
We present two samples for each of Python and C++.
(Python: if statement)
A, D = map(int, input().split())
if A <= D:
print("Yes")
else:
print("No")
(Python: conditional operator)
A, D = map(int, input().split())
print("Yes" if A <= D else "No")
(C++: if statement)
#include <iostream>
using namespace std;
int main() {
int A, D;
cin >> A >> D;
if (A <= D) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
(C++: conditional operator)
#include <iostream>
using namespace std;
int main() {
int A, D;
cin >> A >> D;
cout << (A <= D ? "Yes" : "No") << endl;
}
投稿日時:
最終更新: