Description
输入n个成绩,打印出所有低于平均分的分数(注意:ave = s/n中s 为float或ave = (float)s/n)。
Input
多个测试数据
每个测试数据一行,在这行中先输入分数的个数n(1<=n<=100),然后紧跟着输入n个整数(代表分数)
Output
对于每个测试数据,输出一行按照输入顺序输出所有低于(<)平均分的分数,中间用一个空格隔开,如果没有低于平均分的那么只输出一个空行
Sample Input
3 40 50 60
2 90 80
4 10 10 90 80
Sample Output
40
80
10 10
Source
Code
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
int n;
while(~scanf("%d",&n))
{
int sum=0;
int a[110]={0};
for(int i=0;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
float ave=(float)sum/n;
int flag=0;
for(int j=0;j<n;j++)
{
if(a[j]<ave)
{
if(flag==0)///保证最后一个数字后面没有空格
cout<<a[j];
else
cout<<" "<<a[j];
flag=1;
}
}
cout<<endl;
}
}