문제 출처 :
https://www.acmicpc.net/problem/4344
저는 해당 문제를 다음과 같이 풀었습니다.
#include <iostream>
#include <vector>
using namespace std;
int main(){
//(1 ≤ N ≤ 1000, N은 정수)
int c, N, temp, sum ;
float avg, overRate ;
vector <int> students ;
vector <float> overRates ;
cin >> c ;
for(int k = 0 ; k < c ; k++){
cin >> N ;
sum = 0 ;
for(int i = 0 ; i < N ; i++){
cin >> temp ;
students.push_back(temp) ;
sum += students[i] ;
}
avg = sum / N ;
overRate = 0 ;
for(int i = 0 ; i < N ; i++){
if(students[i] > avg)
overRate += 100 ;
}
overRate /= N ;
overRates.push_back(overRate) ;
students.clear() ;
}
for(int k = 0 ; k < c ; k++){
printf("%5.3f%%\n", overRates[k]) ;
}
return 0 ;
}
https://github.com/gurcks8989/CodingTest/blob/master/BackJoon/HPS/P4344_Above_average.cpp
훈수, 조언 언제나 환영입니다.