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

大侠帮我看看我的程序怎么老是WA啊!!!

Posted by Vi_King at 2006-12-01 21:08:40 on Problem 2163
#include <stdio.h>

float pi(float *num,int i,int k)
{
	int j;

	float sum=0;

	for(j=i-k+1;j<=i;j++)
	{
		sum+=num[j-1];
	}

	return sum/k;
}

int main(){
	int m,n,k;

	int i,j;

	float price[10000],pim,pin;

	int bull=0,bear=0;

	scanf("%d%d%d",&m,&n,&k);
	
	for(i=0;i<k;i++)
	{
		scanf("%f",&price[i]);
	}

	for(i=n;i<k;i++)
	{
		pim=pi(price,i,m);
		pin=pi(price,i,n);
		if(pim>pin)
		{
			if(i==n)
			{
				printf("BUY ON DAY %d\n",i);
				bull=1;
				bear=0;
			}
			else if(bear==1)
			{
				printf("BUY ON DAY %d\n",i);
				bull=1;
				bear=0;
			}
			else
			{
				bull=1;
				bear=0;
			}
		}
		else
		{
			if(i==n)
			{
				printf("SELL ON DAY %d\n",i);
				bear=1;
				bull=0;
			}
			else if(bull==1)
			{
				printf("SELL ON DAY %d\n",i);
				bear=1;
				bull=0;
			}
			else
			{
				bear=1;
				bull=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