# UVa 10370 ### 題目連結:[UVa10370](http://domen111.github.io/UVa-Easy-Viewer/?10370) ### 題述: 據說,90%的大學一年級新生期望他們自己的成績能在全班平均之上,請你來幫忙驗證看看他們有沒有達成目標。 --- 輸入的第一列有一個整數 C 代表以下有多少組測試資料。每組資料的第一個整數 N 代表班級總人數 ( 1 <= N <= 1000 )。接下來有N個以空白或換行來間隔的整數,代表每個學生的期末總成績 ( 0 <= 分數 <= 100 )。 --- 對每組測試資料輸出一列,算出有多少百分比的學生成績比全班平均高,請四捨五入到小數第三位。 ### c++ code: ```cpp= #include<iostream> #include<cstdio> using namespace std; int main() { //------------------------------------------------ #ifdef local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //------------------------------------------------ int n ; cin >> n ; while ( n != 0 ) { n -= 1 ; int a ; int avr = 0 ; double q = 0 ; cin >> a ; int sc[a] ; for ( int i = 0 ; i < a ; i++ ) { cin >> sc[i] ; avr += sc[i] ; } avr /= a ; for ( int i = 0 ; i < a ; i++ ) { if ( sc[i] > avr ) { q += 1 ; } } q /= a ; q *= 100 ; printf("%.3f%\n",q) ; } return 0; } ``` :::success **``sample input``** 5 5 50 50 70 80 100 7 100 95 90 80 70 60 50 3 70 90 80 3 70 90 81 9 100 99 98 97 96 95 94 93 91 ::: :::success **``sample output``** 40.000% 57.143% 33.333% 66.667% 55.556% ::: #### [返回首頁](https://hackmd.io/@fkleofk/APCS#10370) ###### tags: `APCS選修` `C++` `UVa`