-
Notifications
You must be signed in to change notification settings - Fork 38
/
1062.cpp
54 lines (51 loc) · 1.63 KB
/
1062.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
#include <stack>
#include <stdio.h>
int main(){
int n,i,j, flag, flag1,flag2;
int num[1001];
while(1){
scanf("%d",&n);
if(n == 0) break;
while(1){
j = 1;
flag = 0;
flag1 = 0;
std::stack<int> pilha;
for(i = 1; i <= n; i++){
scanf("%d",&num[i]);
if(num[i] == 0){
flag = 1;
printf("\n");
break;
}
}
i = 1;
while(1){
if(i > n) break;
if(flag1 == 1) break;
if(flag == 1) break;
while(1){
if(!pilha.empty() && pilha.top() == num[i]){
pilha.pop();
break;
}else if(j <= n){
pilha.push(j);
j++;
if(pilha.top() == num[i]){
pilha.pop();
break;
}
}else{
flag1 = 1;
break;
}
}
i++;
}
if(flag == 1) break;
if(pilha.empty()) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}