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

Re:那位大侠帮忙看一下,实在不知道为什么WA了?

Posted by zqykiki at 2006-08-08 10:38:06 on Problem 1477
In Reply To:Re:那位大侠帮忙看一下,实在不知道为什么WA了? Posted by:zqykiki at 2006-08-08 10:35:22
初始化的地方错了,应在循环内将k 和m置0
改为:
#include<iostream.h>
int main()
{
	int n,m,k,M[50],i,j,ave;
	m=k=j=0;
	cin>>n;
	while(n!=0)
	{
		k=m=0;
		for(i=0;i<n;i++)
		{
			cin>>M[i];
			m+=M[i];
		}
		ave=m/n;
			for(i=0;i<n;i++)
			{
				if(M[i]>ave)
				{
					k+=M[i]-ave;
				}
			}
		j++;
		
		cout<<"Set #"<<j<<endl;
		cout<<"The minimum number of moves is"<<' '<<k<<'.'<<endl;
		cout<<endl;
		cin>>n;
	}
	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