Problem Statement
We have the following
3
×
3
3 \times 3
3×3 board with integers from
1
1
1 through
9
9
9 written on it.
You are given two integers
A
A
A and
B
B
B between
1
1
1 and
9
9
9, where
A
<
B
A < B
A<B.
Determine if the two squares with
A
A
A and
B
B
B written on them are adjacent horizontally.
Constraints
- 1 ≤ A < B ≤ 9 1 \le A < B \le 9 1≤A<B≤9
- A A A and B B B are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print Yes
if the two squares with
A
A
A and
B
B
B written on them are adjacent horizontally, and No
otherwise.
Sample 1
Input | Output |
---|---|
7 8 | Yes |
The two squares with
7
7
7 and
8
8
8 written on them are adjacent horizontally, so print Yes
.
Sample 2
Input | Output |
---|---|
1 9 | No |
Sample 3
Input | Output |
---|---|
3 4 | No |
题意
在一块 3 × 3 3 \times 3 3×3 的板上有整数 1 − 9 1-9 1−9。给定两个数 A , B A,B A,B, A , B A,B A,B 在 1 − 9 1-9 1−9之间,且 A < B A < B A<B。判断 A , B A,B A,B 是否相邻。
分析
相邻是指
A
,
B
A,B
A,B在同一行,并且
A
=
B
−
1
A = B - 1
A=B−1。因为
A
A
A 比
B
B
B 小,所以如果
A
A
A 在第3列的话(也就是
A
%
3
=
=
0
A \% 3 == 0
A%3==0),
A
,
B
A,B
A,B 就在上下两行,不符合规定。
程序用if语句判断一下就行了。
代码
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main(){
cin >> a >> b;
if (a == b - 1 && a % 3 != 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}