Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:那位大侠帮忙看一下,实在不知道为什么WA了?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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator