반응형
SMALL
C
#include<stdio.h>
int main()
{
int c, n;
scanf("%d", &c);
int i =0, j =0;
int cnt, sum=0;
double avg = 0;
for ( i =0; i<c ; i++)
{
scnaf("%d",&n);
int array[n]={0, };
avg = 0;
cnt = 0;
for( j =0; j<n; j++)
{
scanf("%d",array[j]);
sum += array[j];
}
avg = (double)sum/n;
for( j =0; j< n; j++)
{
if(avg < array[j])
cnt++;
}
printf("%.3f%%\n",(double)cnt*100/n);
}
return 0;
}
C++
#include<iostream>
using namespace std;
int main()
{
int c, n;
int cnt= 0, j=0 ,i=0 ;
double avg=0.0;
int sum =0;
cin >> c;
for(i=0 ; i <c ; i++)
{
cin >> n;
int array[n] = {0 , };
avg = 0.0;
cnt = 0;
sum =0;
for( j =0; j<n ; j++)
{
cin>>array[j];
sum += array[j];
}
avg = (double)sum/n;
for(j=0; j<n ; j++)
{
if(array[j]>avg) cnt++;
}
cout<<(double)cnt*100/n<< "%"<<endl;
}
return 0;
}
Python
c = int(input())
for i in range(c):
scores = list (map(int, input().split()))
avg = sum(scores[1:])/scores[0]
cnt = 0
for i in scores[1:]:
if i > avg:
cnt += 1
per = cnt/scores[0])*100
print('%.3f'%per + '%')
반응형
LIST
'programming > 알고리즘 풀이' 카테고리의 다른 글
백준 -4673번 [C/C++/Python] - 함수 셀프넘버 (0) | 2021.12.01 |
---|---|
백준 1546 -[C/C++/PYTHON] 1차원배열 (0) | 2021.11.29 |
백준 10951번- [C/C++/Python] while문 (0) | 2021.11.29 |
백준 2739번 [C ,C++ , PyThon] -for문 (0) | 2021.11.28 |
백준 2884번 [C,C++ ,Python] IF문 (0) | 2021.11.26 |