#44927: 各位有沒有注意到一個小細節?


yp11351280@yphs.tp.edu.tw (710-43)

學校 : 臺北市私立延平高級中學
編號 : 276272
來源 : [1.164.243.217]
最後登入時間 :
2025-04-08 22:18:39
c067. 00591 - Box of Bricks -- UVa591 | From: [203.72.178.1] | 發表日期 : 2024-12-26 17:17

#include<iostream>
#define MAX 50
using namespace std;
int main(){
    int n, j=1,sum,av,move,h[MAX];
    while(cin>>n,n!=0){
        sum=0;
        for(int i=0;i<n;i++) {cin>>h[i];sum+=h[i];}
        av=sum/n;
        move=0;
        for(int i=0;i<n;i++) if(h[i]>av) move+=(h[i]-av);
        cout<<"Set #"<<j++<<endl;
        cout<<"The minimum number of moves is "<<move<<"."<<endl<<endl; //不管單複數,都是moves
    }
}

 
#45664: Re: 各位有沒有注意到一個小細節?


marsissocute@gmail.com (Jamin Ben)

學校 : 康橋雙語學校
編號 : 245157
來源 : [59.120.140.251]
最後登入時間 :
2024-09-05 20:04:03
c067. 00591 - Box of Bricks -- UVa591 | From: [220.137.199.140] | 發表日期 : 2025-03-29 10:50

#include
#define MAX 50
using namespace std;
int main(){
    int n, j=1,sum,av,move,h[MAX];
    while(cin>>n,n!=0){
        sum=0;
        for(int i=0;i>h[i];sum+=h[i];}
        av=sum/n;
        move=0;
        for(int i=0;iav) move+=(h[i]-av);
        cout<<"Set #"<        cout<<"The minimum number of moves is "<    }
}


這是因為"moves"不是再講答案,是再說最少要動的次數,因此文法是對的,但如果是"The minimum number is 0 moves"就是錯的。

 
ZeroJudge Forum