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 snailly18 at 2006-07-21 16:33:07 on Problem 1492
#include<iostream>
#define MAX 1000
using namespace std;
main()
{
	int a[MAX];
	int i=1;
	do
	{
		cin>>a[0];
		int n=0;
		int cup=0,cdown=0;
		int up=0,down=0;
		int flag=-1;
		int t=0;
		if(a[0]==0)
		    break;
		i=1;
		do scanf("%d",&a[i]);
		while(a[i++]!=0);
		n=i-1;
		for(i=1;i<n;i++)
		{
			if(a[i-1]<a[i])
			{
				cup=1;
				flag=0;
				break;
			}
			if(a[i-1]>a[i])
			{
				cdown=1;
				flag=1;
				break;
			}
		}
		for(i=1;i<n;i++)
		{
			if(a[i-1]<a[i])
			{
				up++;
				if(flag==1)
					cup++;
				flag=0;
			}
			if(a[i-1]>a[i])
			{
				down++;
				if(flag==0)
					cdown++;
				flag=1;
			}
			if(a[i-1]==a[i])
			{
				if(flag==0)
					up++;
				if(flag==1)
					down++;
			}
		}
		if(cup==0) cup=1;
		if(cdown==0) cdown=1;
		printf("Nr values = %d %f %f\n",n,float(up)/cup,float(down)/cdown);
	}while(1);
}
题目给出的数据都对了啊,式输入输出的问题吗?
哪位大哥指导一下,或者给几组错误数据,或者给个ac的代码都好,谢谢

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