A - Is it rated? 解説 by en_translator
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” (https://atcoder.jp/contests/abs).
Given two integers \(R\) and \(X\) (where \(X\) is either \(1\) or \(2\)), you are asked to print Yes
or No
depending on the value \(X\) and the range of \(R\).
Two components are needed to write a program that solves such a problem: input and output of integers, and conditional branches. For the conditional branch, one can write a doubly nested conditional branch to clarify the logical structure, in which you first divide cases depending on the value \(X\) (\(1\) or \(2\)), and then further perform another case analysis in each branch depending on the value \(R\).
How to represent these components depends on your programming language. Please refer to the following sample code (C++ or Python) or tutorials of your language.
Especially note that, if you want to check if a variable \(x\) is between \(A\) and \(B\), you can write A <= x <= B
in Python, while you need to write A <= x && x <= B
or A <= x and x <= B
in C++.
Sample code (C++) :
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, x;
cin >> r >> x;
if (x == 1) {
if (1600 <= r and r <= 2999) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} else {
if (1200 <= r and r <= 2399) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
Sample code (Python) :
r, x = map(int, input().split())
if x == 1:
if 1600 <= r <= 2999:
print("Yes")
else:
print("No")
else:
if 1200 <= r <= 2399:
print("Yes")
else:
print("No")
投稿日時:
最終更新: