Skip to content

Instantly share code, notes, and snippets.

@glowing713
Created July 18, 2019 12:37
Show Gist options
  • Save glowing713/78ade54d3354a202c6a278ca61eac72e to your computer and use it in GitHub Desktop.
Save glowing713/78ade54d3354a202c6a278ca61eac72e to your computer and use it in GitHub Desktop.
백준 4344번 평균은 넘겠지
#include <iostream>
using namespace std;
int main(void){
int arr[1000] = {0,};
int cycle = 0, snum = 0, sum = 0, avg = 0;
cin >> cycle;
for(int i = 0; i < cycle; ++i){
cin >> snum;
for(int j = 0; j < snum; ++j){
cin >> arr[j];
}
for(int k = 0; k < snum; ++k){
sum += arr[k];
}
avg = sum/snum;
int cnt = 0;
for(int l = 0; l < snum; ++l){
if(arr[l] > avg) ++cnt;
}
/* 이렇게도 가능하다.
cout.precision(3);
cout << (double)cnt/snum*100 << "%" << endl;
*/
printf("%.3f%%\n", (double)cnt/snum*100);
sum = 0;
avg = 0;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment