A - Mike and Cellphone
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?
InputThe 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.
OutputIf 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.
ExamplesInput3
586OutputNOInput2
09OutputNOInput9
123456789OutputYESInput3
911OutputYESNoteYou can find the picture clarifying the first sample case in the statement above.
题意:给定一个0-9的数字键盘,随后输入一个操作序列,问该操作序列在键盘上形成的手势是否是唯一的,是则输出YES,否则为NO。
本题可以做一个响亮的边界处理,我们设上下左右方向的向量分别为U、D、L、R,当不可向该方向移动时对应的字母值为1。例如当操作序列含0时,左右下都不可移动,则L=R=D=0;
附AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; int main(){
int n;
char s[];
while(cin>>n>>s){
int U=,D=,L=,R=;
for(int i=;i<n;i++){
if(s[i]=='')
D=R=L=;
if(s[i]==''||s[i]==''||s[i]=='')//上
U=;
if(s[i]==''||s[i]==''||s[i]=='')//左
L=;
if(s[i]==''||s[i]==''||s[i]=='')//右
R=;
if(s[i]==''||s[i]=='')//下
D=;
}
if(U==&&D==&&R==&&L==)//当所有方向都不可走时,即手势唯一
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return ;
}
A - Mike and Cellphone的更多相关文章
- CodeForces 689A Mike and Cellphone (模拟+水题)
Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...
- A. Mike and Cellphone(Round 361 Div.2)
写一半去开程序的时候不小心关了网页,LOFTER我都不奢望加入代码高亮,最起码我关闭的时候弹个对话框,再不济也给我定时保存一下草稿吧. A. Mike and Cellphone time limit ...
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题
A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...
- 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 standar ...
- codeforces 689A A. Mike and Cellphone(水题)
题目链接: A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input s ...
- codeforces 361 A - Mike and Cellphone
原题: Description While swimming at the beach, Mike has accidentally dropped his cellphone into the wa ...
- B - Mike and Cellphone(map)
Problem description While swimming at the beach, Mike has accidentally dropped his cellphone into th ...
- CodeForces 689A -Mike and Cellphone
题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=412142 题目大意: 给定一个0-9数字键盘,随后输入一个操 ...
- CoderForces 689A Mike and Cellphone (水题)
题意:给定一个手机键盘数字九宫格,然后让你判断某种操作是不是唯一的,也就是说是不是可以通过平移也能实现. 析:我的想法是那就平移一下,看看能实现,就四种平移,上,下,左,右,上是-3,要注意0变成8, ...
随机推荐
- php empty、isset、is_null区别
有关 PHP 的 empty(),isset() 还有 is_null() 这三个函数的用法讨论得已经很多了,而且很多资料也未必能说得很清楚.这里再重复一次,但不是从概念去说,直接用程序例子来说话,应 ...
- HDU-3681-Prison Break(BFS+状压DP+二分)
Problem Description Rompire is a robot kingdom and a lot of robots live there peacefully. But one da ...
- 【git】强制覆盖本地代码
[git]强制覆盖本地代码(与git远程仓库保持一致) 2018年04月27日 23:53:57 不才b_d 阅读数:21145 版权声明:本文为博主不才b_d原创文章,未经允许不得转载. || ...
- MySQL 更新和删除
更新和删除的操作SQL语句比較简单,只是要注意使用UPDATE的时候.要注意WEHER条件的限制,以下的语句是仅仅更新id为10005的email地址,假设不加WHERE语句限制,那么将表中全部的em ...
- 【剑指Offer学习】【面试题62:序列化二叉树】
题目:请实现两个函数,分别用来序列化和反序列化二叉树. 解题思路 通过分析解决前面的面试题6.我们知道能够从前序遍历和中序遍历构造出一棵二叉树.受此启示.我们能够先把一棵二叉树序列化成一个前序遍历序列 ...
- java基础知识查漏 三
一.Servlet 和Jsp的生命周期 1.Servlet生命周期 Servlet是运行在Servlet容器(有时候也叫Servlet引擎,是web服务器和应用程序服务器的一部分,用于在发 ...
- 2018-11-9-匿名函数&递归函数初识
1.匿名函数(lambda) 2.递归函数初识
- Find out when memory leaks are a concern and how to prevent them
Handling memory leaks in Java programs Find out when memory leaks are a concern and how to prevent t ...
- LightOJ1220 —— 质因数分解
题目链接:https://vjudge.net/problem/LightOJ-1220 1220 - Mysterious Bacteria PDF (English) Statistics ...
- 近期测试BUG总结
前些日子上线了新版的app,在上线后发现了几个重大的bug,在此总结,在以后的测试工作中需要额外的关注. 需求流程bug 页面刷新bug 标签栏刷新bug 第一个bug出现的原因是产品需求与运营实际操 ...


