zoukankan      html  css  js  c++  java
  • A

    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-9的数字键盘,随后输入一个操作序列,问该操作序列在键盘上形成的手势是否是唯一的,是则输出YES,否则为NO。

    本题可以做一个响亮的边界处理,我们设上下左右方向的向量分别为U、D、L、R,当不可向该方向移动时对应的字母值为1。例如当操作序列含0时,左右下都不可移动,则L=R=D=0;

    附AC代码:

     1 #include<iostream> 
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 int main(){
     8     int n;
     9     char s[10000];
    10     while(cin>>n>>s){
    11         int U=0,D=0,L=0,R=0;
    12         for(int i=0;i<n;i++){
    13         if(s[i]=='0')
    14         D=R=L=1;
    15         if(s[i]=='1'||s[i]=='2'||s[i]=='3')//
    16         U=1;
    17         if(s[i]=='1'||s[i]=='4'||s[i]=='7')//
    18         L=1;
    19         if(s[i]=='3'||s[i]=='6'||s[i]=='9')//
    20         R=1;
    21         if(s[i]=='7'||s[i]=='9')//
    22         D=1;    
    23         }
    24         if(U==1&&D==1&&R==1&&L==1)//当所有方向都不可走时,即手势唯一 
    25         cout<<"YES"<<endl;
    26         else
    27         cout<<"NO"<<endl;
    28     }
    29     return 0;
    30 }
  • 相关阅读:
    系统管理员必须掌握的20个Linux监控工具
    JavaWeb基础—MVC与三层架构
    JavaWeb基础—JavaBean
    JavaWeb基础—JSP
    myeclipse(eclipse)IDE配置
    JavaWeb基础—会话管理之Session
    JavaWeb基础—会话管理之Cookie
    JavaWeb基础—项目名的写法
    JavaWeb基础—HttpServletRequest
    JavaWeb基础—VerifyCode源码
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5655966.html
Copyright © 2011-2022 走看看