Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不同意stl的观点?怎么是错误?悉求大虾指点

Posted by swun at 2008-05-24 18:02:41 on Problem 1363
#include <stack>
#include <iostream>

using namespace std;

int main(void) {
	int arr[1010], n, i, flag;
	stack<int> a;
	stack<int> b;

	while (cin >> n) {
		if (!n)		break;
		while (cin >> arr[0]) {
		if (!arr[0]) {
			cout << endl;
			break;
		} 
		for (i = 1; i < n; i++)
			cin >> arr[i];
		for (i = n; i > 0; i--)
			a.push(i);
		flag = 1;
		i = 0;
		while (i < n) {
			if (b.empty()) {
				if (a.top() == arr[i]) {
					i++;
					a.pop();
				} else {
					b.push(a.top());
					a.pop();
				}
			} else {
				if (b.top() == arr[i]) {
					i++;
					b.pop();
				} else {
					if (a.empty()) {
						flag = 0;
						break;
					} else {
						b.push(a.top());
						a.pop();
					}
				}
			}
		}
		if (flag)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator