# whust 2016 warm up E||codeforces 689 A. Mike and Cellphone (模拟)

Posted by 111qqz on Monday, July 18, 2016

## TOC

cf689A

``````/* ***********************************************
Author :111qqz
Created Time :2016年07月18日 星期一 12时56分28秒
File Name :code/2016whust/E.cpp
************************************************ */

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long LL;
#define pi pair < int ,int >
#define MP make_pair

using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
const int inf = 0x3f3f3f3f;

const int up[15]={8,-1,-1,-1,1,2,3,4,5,6};
const int down[15]={-1,4,5,6,7,8,9,-1,0,-1};
const int l[15]={-1,-1,1,2,-1,4,5,-1,7,8};
const int r[15]={-1,2,3,-1,5,6,-1,8,9,-1};
int n;
string st;

bool solve()
{
bool flag = true;
for ( int i = 0 ; i < n ; i++)
{
int x = st[i]-'0';
//	cout<<"x:"<<x<<" x+up[x]"<<x+up[x]<<endl;
x = up[x];
if (x==-1)
{
flag = false;
//	    cout<<"uuuuu"<<endl;
break;
}
}
if (flag) return true;

flag = true;
for ( int i = 0 ; i < n ; i++)
{
int x = st[i]-'0';
x = down[x];
if (x==-1)
{
flag = false;
//	    cout<<"ddd"<<endl;
break;
}
}
if (flag) return true;

flag = true;
for ( int i = 0 ; i  < n;  i++)
{
int x = st[i]-'0';
x = l[x];
if (x==-1)
{
flag = false;
//	    cout<<"lll"<<endl;
break;
}
}

if (flag) return true;
flag = true;

for ( int i =  0 ; i  < n ; i++)
{
int x = st[i]-'0';
x = r[x];
if (x==-1)
{
flag = false;
//	    cout<<"rrr:::"<<endl;
break;
}
}
if (flag) return  true;

return false;

}
int main()
{
#ifndef  ONLINE_JUDGE
freopen("code/in.txt","r",stdin);
#endif

cin>>n;
cin>>st;
if (!solve())
{
puts("YES");
}
else
{
puts("NO");
}

#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
``````

「真诚赞赏，手留余香」