Mike and Cellphone

xiaoxiao2021-02-28  70

A. Mike and Cellphone time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard 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.

题意:给你一串数字,问这一串数字的按键顺序是不是唯一的?

思路:按键顺序唯一有几种情况,首先,不含有0、7、9这三个数的肯定是NO,然后判断是否有0,若有0,那么只需要第一行有数字即可;若没有0,那么需要第一行、第三行、第一列、第三列都有数字。

code:

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define INF 0x3f3f3f3f int n; char a[12]; bool dx[5],dy[5]; int main() { scanf("%d",&n); scanf("%s",a); int u = 0; for(int i=0;i<=n-1;i++) if(a[i] == '0' || a[i] == '7' || a[i] == '9') { u = 1; break; } if(!u) { printf("NO\n"); return 0; } int x=0,y=0; int flag = 0; for(int i=0;i<=n-1;i++) { if(a[i] == '0') { flag = 1; continue; } if((a[i] - 48)%3 == 0) x = (a[i]-48)/3; else x = (a[i]-48)/3 +1; y = (a[i]-48) % 3; if(x == 3 ) x = 0; dx[x] = 1; dy[y] = 1; } if(flag) { if(dx[1]) printf("YES\n"); else printf("NO\n"); } else { if(dx[0] && dx[1] && dy[0] && dy[1]) printf("YES\n"); else printf("NO\n"); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-66260.html

最新回复(0)