标签:des style blog http color io os ar for
Description
Input
Output
Sample Input
5 1 2 3 4 5 5 4 1 2 3 0 6 6 5 4 3 2 1 0 0
Sample Output
Yes No Yes
分析:栈
代码:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <stack> 5 using namespace std; 6 7 const int maxn = 100005; 8 9 stack<int> s; 10 int a[maxn]; 11 12 int main() { 13 int n; 14 int num; 15 bool flag = false; 16 while(scanf("%d",&n) && n ) { 17 if(flag) puts(""); 18 flag = true; 19 while(1) { 20 scanf("%d", &a[1]); 21 if(a[1] == 0) break; 22 for(int i = 2; i <= n; i++) { 23 scanf("%d",&a[i]); 24 } 25 while(!s.empty() ) s.pop(); 26 int i = 1; int j = 1; 27 for(int i = 1; i <= n; i++) { 28 s.push(i); 29 while(!s.empty() && s.top() == a[j]) { 30 s.pop(); j++; 31 } 32 } 33 if(s.empty()) puts("Yes"); 34 else puts("No"); 35 } 36 } 37 return 0; 38 }
标签:des style blog http color io os ar for
原文地址:http://www.cnblogs.com/zhanzhao/p/3989154.html