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

到底哪里错了啊 sample都过的啊 !!

Posted by fhyvenus at 2008-08-15 10:48:02 on Problem 1492
#include <stdio.h>
#include <string.h>
int main()
{
	int n,a[100],b[100];
	int i,j,t,k;
	int flage,flage1;
	int up,down,up1,down1;
	while(1==scanf("%d",&n))
	{
		if(n==0)
			break;
		i=1;a[1]=n;t=0;up=0;down=0;
		up1=0;down1=0;flage=1;
		memset(b,0,sizeof(b));
		while(1)
		{
			i++;
			scanf("%d",&a[i]);
			if(a[i]==0)
				break;
		}
		for(j=1;j<i-1;j++)
		{
			if((a[j]-a[j+1])==0)
				t++;
			else
			{
				flage=j;
				break;
			}
		}
		if((a[flage]-a[flage+1])>0)
			down=down+t;
		if((a[flage]-a[flage+1])<0)
			up=up+t;
		flage1=0;
		for(j=flage;j<i-1;j++)
		{
			if((a[j]-a[j+1])>0)
			{
				down++;
				flage1=0;
			}
			if((a[j]-a[j+1])<0)
			{
				up++;
				flage1=0;
			}
			if((a[j]-a[j+1])==0)
			{
				if(j!=1)
				{
			     	if((a[j]-a[j-1])>0)
			  	    	flage1=1;	
			        if((a[j]-a[j-1])<0)
			     	    flage1=2;
				}
			}
			if(flage1==1)
				up=up+1;
			if(flage1==2)
				down=down+1;
		}
		k=0;
		for(j=1;j<i-1;j++)
		{
			if((a[j]-a[j+1])>0)
			{
				k++;
				b[k]=-1;
			}
			if((a[j]-a[j+1])<0)
			{
				k++;
				b[k]=1;
			}
			if((a[j]-a[j+1])==0)
			{
				k++;
				b[k]=0;
			}
		}
		for(j=1;j<=k;j++)
		{
			if(b[j]==1&&b[j+1]!=1)
				up1++;
			if(b[j]==-1&&b[j+1]!=-1)
				down1++;
		}
		if(up1==0)up1=1;
		if(down1==0)down1=1;
		printf("Nr values = %d:  %f %f\n",i-1,(double)up/up1,(double)down/down1);
	}
	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