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

help ~~~提交好几次了 总是wa 到底是错在哪了 帮我瞧瞧吧

Posted by daiyilin at 2006-03-21 11:51:48 on Problem 1363
#include <iostream>
#include <stack>
using namespace std;
int a[1002];
stack<int> rail;
void main()
{
	int n;
	int i;
	int y;
	//cin>>n;
	//if(n==0) return;
	while(cin>>n && n)
	{
		while(cin>>a[0] && a[0])
		{
			for(i=1;i<n;i++)
			{
				cin>>a[i];
			}
			i=0;//表示输出的列的下标
			for(y=1;y<=n;y++)//y从1到n是输入列的值
			{
				if(y==a[i]) 
					i++;
				else if(!rail.empty() && rail.top()==a[i])
				{
					i++;
					rail.pop();
					y--;
				}
				else
				{
					rail.push(y);
				}
			}
			while(1)
			{
				if(i==n) {cout<<"Yes"<<endl;break;}
				if(!rail.empty() && a[i]==rail.top())
				{
					rail.pop();
					i++;
					continue;
				}
				else
					{cout<<"No"<<endl;break;}
			}
		}
		while(!rail.empty())
			rail.pop();
		//cin>>n;
		//if(n==0) break;
		cout<<endl;
	}
}

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