CodeForces 689A 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.

题意:给出一个手机键盘,对于给出的数字,是否有其他数字的按键方式和他们一样
思路:只要给出的数字全部不能向左移,全部不能向右移,全部不能向下移,全部不能向上移即可。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,i,j,k,l,left,right,up,down;
	char str[110000];
	while(scanf("%d",&n)!=EOF)
	{
		scanf("%s",str);
	    left=right=up=down=1;
		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'||str[i]=='0')
			left=0;
			if(str[i]=='7'||str[i]=='9'||str[i]=='0')
			down=0;
			if(str[i]=='6'||str[i]=='9'||str[i]=='3'||str[i]=='0')
			right=0;
		}
		if(down||up||left||right)
		printf("NO\n");
		else
		printf("YES\n"); 
	}
	return 0;
 } 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值