#UVa:10370-Above Average

照著題目算即可得解。

C++(0.024)

/*******************************************************/
/* UVa 10370 Above Average                             */
/* Author: LanyiKnight [at] knightzone.studio             */
/* Version: 2011/12/14                                 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;

int main(){
  int C, N;
  float score[1005], average, percent;
  while( scanf( "%d", &C ) != EOF ){
    for( int i = 1 ; i <= C ; i++ ){
      scanf( "%d", &N );
      average = 0.0;
      for( int j = 0 ; j < N ; j++ ){
        scanf( "%f", &score[j] );
        average += score[j];
      }
      average /= N;
      percent = 0.0;
      for( int j = 0 ; j < N ; j++ ){
        if( score[j] > average ) percent++;
      }
      percent /= N;
      percent *= 100;
      printf( "%.3f%%\n", percent );
    }
  }
  return 0;
}
廣告

Comment

There is no comment on this post. Be the first one.

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料

%d 位部落客按了讚: