-
Notifications
You must be signed in to change notification settings - Fork 12
/
1802.cpp
66 lines (60 loc) · 1.1 KB
/
1802.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<stack>
using namespace std;
stack<char> S;
char str[10];
int top;
void push(int x)
{
for(int i=top; i<=x; i++)
{
S.push(i+'0');
}
top=x+1;
}
int main()
{
//freopen("in.txt","r",stdin);
int k,n;
scanf("%d",&n);
while(n--)
{
scanf("%d %s",&k,str+1);
while(!S.empty()) S.pop();
top=1;
push(str[1]-'0');
bool mark=true;
for(int i=1; i<=k; i++)
{
if(S.empty())
{
push(str[i]-'0');
i--;
continue;
}
if(S.top()==str[i])
{
S.pop();
}
else if( S.top()<str[i] )
{
push(str[i]-'0');
i--;
}
else
{
mark=false;
break;
}
}
if(mark)
printf("yes\n");
else
printf("no\n");
}
return 0;
}//Parsed in 0.105 seconds