LRJ-Example-06-02-Uva514
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LRJ-Example-06-02-Uva514相关的知识,希望对你有一定的参考价值。
1 #define _CRT_SECURE_NO_WARNINGS 2 3 #include<cstdio> 4 #include<stack> 5 using namespace std; 6 const int MAXN = 1000 + 10; 7 8 int n, target[MAXN]; 9 10 int main() { 11 // scanf() returns the number of input items matched and assigned 12 while (scanf("%d", &n) == 1 && n != 0) { 13 while (true) { 14 // the last line of the block contains just 0 15 scanf("%d", &target[1]); 16 if (target[1] == 0) { printf("\n"); break; } 17 18 for (int i = 2; i <= n; i++) 19 scanf("%d", &target[i]); 20 21 stack<int> s; 22 // assume an input array input[] containing 1, 2, ..., n in sequence, input[i] == i 23 // A is the index of input[], and B is the index of target[] 24 int A = 1, B = 1; 25 bool ok = true; 26 while (B <= n) { 27 if (A == target[B]){ 28 A++; 29 B++; 30 } else if (!s.empty() && s.top() == target[B]){ 31 s.pop(); 32 B++; 33 } else if (A <= n){ 34 s.push(A++); 35 } else { 36 ok = false; 37 break; 38 } 39 } 40 41 printf("%s\n", ok ? "Yes" : "No"); 42 } 43 } 44 return 0; 45 }
以上是关于LRJ-Example-06-02-Uva514的主要内容,如果未能解决你的问题,请参考以下文章
使用 TCL 捕获 SYSlog(端口 514)UDP/TCP?