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
Hint
You can find the picture clarifying the first sample case in the statement above.
题意:一个人忘了手机密码,这个手机密码是个图形,问你这个图形的路径是否唯一,(如果不唯一,那末它就可以靠平移得到,就像题目给的那样586和253这两个路径是相同的,可以靠平移得到,所以不唯一)
思路;看能不能平移,就看这个数字在那个位置,比如123,它们就不可以往上平移,147就不可能往左平移。。。。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define INF 1e9
using namespace std;
char str[100];
int main()
{
int n,up,down,left,right,i;
while(scanf("%d",&n)!=EOF)
{
up=right=left=down=1;
scanf("%s",str);
for(i=0;i<n;i++)
{
if(str[i]=='1'||str[i]=='2'||str[i]=='3')
up=0;
if(str[i]=='1'||str[i]=='4'||str[i]=='7')
left=0;
if(str[i]=='3'||str[i]=='6'||str[i]=='9')
right=0;
if(str[i]=='7'||str[i]=='9') down=0;
if(str[i]=='0') down=left=right=0;
}
if(up||down||right||left)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}