标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 27593 | Accepted: 10745 |
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
Source
1 #include<cstdio> 2 #include<stack> 3 using namespace std; 4 int main() 5 { 6 int n,i,j,num[1010]; 7 while(~scanf("%d",&n),n) 8 { 9 while(~scanf("%d",&num[0]),num[0]) 10 { 11 for(i=1;i<n;i++) 12 scanf("%d",&num[i]); 13 stack<int>s; 14 for(j=0,i=1;i<=n;i++) 15 { 16 s.push(i); 17 while(!s.empty()&&s.top()==num[j]) 18 { j++; s.pop(); } 19 20 } 21 if(j==n) 22 printf("Yes\n"); 23 else 24 printf("No\n"); 25 } 26 printf("\n"); 27 } 28 return 0; 29 }
//数组
1 #include<stdio.h> 2 int main() 3 { 4 int n,i,j,t; 5 int a[1010],b[1010]; 6 while(~scanf("%d",&n),n) 7 { 8 while(scanf("%d",&a[0]),a[0]) 9 { 10 for(i=1; i<n ;i++) 11 scanf("%d",&a[i]); 12 t=0; //数组a[]相当于栈,t为栈顶当前所在位置,据While()循环判断条件,t会更新; 13 for(j=0,i=1; i<=n; i++) 14 { 15 b[t++]=i; 16 while(t>0 && b[t-1]==a[j]) //给组数据,自己测试; 6 3 2 1 6 5 4; (while也有循环作用) 17 { t--; j++; } 18 } 19 if(j == n) 20 printf("Yes\n"); 21 else 22 printf("No\n"); 23 } 24 printf("\n"); 25 } 26 return 0; 27 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4582193.html