Codeforces Round #361 (Div. 2) A. Mike and Cellphone

A. Mike and Cellphone
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
input
3
586
output
NO
input
2
09
output
NO
input
9
123456789
output
YES
input
3
911
output
YES
Note

You can find the picture clarifying the first sample case in the statement above.



题意

接收一个n,之后接收一串数字,问你这一串数字构成的形状是否能够平移到这个数字键盘的其他位置并且保证完整,如果能输出NO,反之YES。

代码

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,up,down,left,right;
    char z[15];
    cin>>n;
    cin>>z;
    up=down=left=right=1;
    for(a=0;n>a;a++){
        if(z[a]=='1'||z[a]=='2'||z[a]=='3'){
            up=0;
        }
        if(z[a]=='7'||z[a]=='0'||z[a]=='9'){
            down=0;
        }
        if(z[a]=='1'||z[a]=='4'||z[a]=='7'||z[a]=='0'){
            left=0;
        }
        if(z[a]=='3'||z[a]=='6'||z[a]=='9'||z[a]=='0'){
            right=0;
        }
    }
    if(up||down||left||right){
        cout<<"NO"<<endl;
    }
    else{
        cout<<"YES"<<endl;
    }
    return 0;
}


第一次hack,结果手慢了,被别人抢了,手动尴尬。

猜你喜欢

转载自blog.csdn.net/ontheway0101/article/details/51850403