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

本题目除了用栈的库函数外,也可以直接用数组来模拟!

Posted by datacw at 2011-08-11 11:08:06 on Problem 1363
一下是代码:
#include <iostream>
using namespace std;
int main()
{
	int n;
	int i,j,k;
	int a[1005],pre[1005];
	int stack[1005];
	for(i=1;i<=1000;i++)
		 pre[i]=i;
     	cin>>n;
	  while( n!=0)
	  {
		  while(cin>>a[1])
		  {
			  if(a[1]==0)  break ;
		  for(i=2;i<=n;i++)
			  cin>>a[i];
          i=j=k=1;
		  while(j<=n &&i<=n)
		  {
			  if(a[i]==pre[j])
			  {  
				  i++;j++; 
				  continue;
			  }
			  if(k>1)	 { if(a[i]==stack[k-1])  { i++; k--; continue;}}
					stack[k]=pre[j];
			    	 k++;j++;
		  }
	   if(i<=n )  
	   {
		   for(j=i;j<=n;j++)
			   if(a[j]==stack[k-1]) k--;
			      else break;
	   }
		if(j>n) cout<<"Yes"<<endl;
		  else cout<<"No"<<endl;
	  }
		  cin>>n;
		  if(n!=0)
		    cout<<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