码迷,mamicode.com
首页 > 其他好文 > 详细

UVa 514 (stack的使用) Rails

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

标签:style   blog   http   color   io   os   使用   ar   for   

练习一下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

标签:style   blog   http   color   io   os   使用   ar   for   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!