首页 > 其他 > 详细

UVa 514 (stack的使用) Rails

时间:2014-09-17 18:35:42      阅读:252      评论:0      收藏:0      [点我收藏+]

练习一下stack的使用,还有要注意一下输入的格式,看了好长时间没懂。

 

bubuko.com,布布扣
 1 //#define LOCAL
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <stack>
 6 using namespace std;
 7 
 8 const int maxn = 1000 + 10;
 9 int n, target[maxn];
10 
11 int main(void)
12 {
13     #ifdef LOCAL
14         freopen("514in.txt", "r", stdin);
15     #endif
16 
17     while(scanf("%d", &n) == 1 && n)
18     {
19         while(scanf("%d", &target[1]) == 1 && target[1])
20         {
21             for(int i = 2; i <= n; ++i)    scanf("%d", &target[i]);
22             stack<int> s;
23             int A = 1, B = 1;
24             int ok = 1;
25             while(B <= n)
26             {
27                 if(A == target[B])    { A++; B++; }
28                 else if(!s.empty() && s.top() == target[B])    { s.pop(); B++; }
29                 else if(A <= n) s.push(A++);
30                 else    { ok = 0; break; }
31             }
32             printf("%s\n", ok ? "Yes" : "No");
33         }
34         printf("\n");
35     }
36 
37     return 0;
38 }
代码君

 

UVa 514 (stack的使用) Rails

原文:http://www.cnblogs.com/AOQNRMGYXLMV/p/3977651.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!