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 dynamic_study at 2009-08-21 19:40:59 on Problem 3298
#include<iostream>
using namespace std;
int main()
{
	int n,i,j,t,a[30001],loop,k,MAX,ans;
	bool flag;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>t;
		for(j=0;j<t;j++)
			cin>>a[j];
		MAX=1;
		for(j=0;j<t-1;j++)
		{

			flag=true;
			ans=1;
			for(k=j+1;k<t;k++)
			{
				loop=0;
				if(flag&&loop==0)
				{ 
					if(a[k]<a[k-1])
					{
					ans++;
					flag=false;
					loop=1;
					}
				}
				else if(!flag&&loop==0)
				{
					if(a[k]>a[k-1])
					{
					ans++;
					flag=true;
					loop=1;
					}
				}
				if(loop==0)
					break;
			}
			if(ans>MAX)
				MAX=ans;
			
		}
		cout<<MAX<<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