先看题面
In the figure shown in the image below, are the points numbered aa and bb directly connected by a line segment?
Constraints
- 1 \leq a \lt b \leq 101≤a<b≤10
- aa and bb are integers.
大意就是如果此图中俩点之间有一条线段连着,那么输出Yes,否则输出No。
这么一来就很简单了,就是判断两数是否相邻就行了,但除此之外,10与1是相邻的。
代码
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a+1==b||a-1==b||(a==10&&b==1)||(a==1&&b==10)){
cout<<"Yes";
}else cout<<"No";
}
本作者第一篇文,还求过审