A - Mike and Cellphone
Description
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253":
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
Input
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
Output
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
Sample Input
3
586
NO
2
09
NO
9
123456789
YES
3
911
YES
题意:
给出一个锁屏,问存不存在其他锁屏密码跟改密码有同样的移动模式(例如0->9和8->6 移动方向 距离都一样)
分析:
可以记录每个数字上下左右。然后枚举移动方向和距离,将整个号码拖着移动。看看合不合法。
也可以直接判断该锁屏是否都可以向相同的方向移动(是否都不存在在同一个边界上)如果可以则输出“NO”.
#include <iostream> #include<cstdio> using namespace std; int main() { int n,x=0,y=0,z=0,l=0; char a[15]; scanf("%d",&n); cin>>a; for(int i=0;i<n;i++) { if(a[i]!='1'&&a[i]!='2'&&a[i]!='3') x++; if(a[i]!='9'&&a[i]!='7'&&a[i]!='0') y++; if(a[i]!='1'&&a[i]!='4'&&a[i]!='7'&&a[i]!='0') z++; if(a[i]!='3'&&a[i]!='6'&&a[i]!='9'&&a[i]!='0') l++; } if(x==n||y==n||z==n||l==n) printf("%s ","NO"); else printf("%s ","YES"); return 0; }