A - Nine Editorial 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).
This problem requires to receive the input, determine if two squares with \(A\) and \(B\) are adjacent horizontally, and print the result.
The input can be received as an integer type, which is provided in each language. For example, in C++ you can write as follows:
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
Then we determine if two squares with \(A\) and \(B\) written on them are adjacent horizontally. Since there are only six pairs of horizontally-adjacent \(A\) and \(B\) as \(A<B\), we can write as follows:
bool answer=false;
if(a==1&&b==2) answer=true;
if(a==2&&b==3) answer=true;
if(a==4&&b==5) answer=true;
if(a==5&&b==6) answer=true;
if(a==7&&b==8) answer=true;
if(a==8&&b==9) answer=true;
Now that we know whether the squares with \(A\) and \(B\) written on them are horizontally adjacent or not, all that left is to print the result. Print Yes
if they are adjacent, and No
otherwise.
if(answer) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
Combining the snippets above, you can solve the problem.
On second thought, two squares with \(A\) and \(B\) written on them are horizontally adjacent if and only if \(A\) is indivisible by \(3\) and \(A+1=B\), as \(A<B\); so we can write the following concise code.
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a%3!=0&&a+1==b) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
posted:
last update: