#include<cstdio>
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
char a[50],b[50];
int n;
cin>>n;
bool flag;
double temp,average=0.0;
int cnt=0;
for(int i=0;i<n;i++)
{
flag=true;
scanf("%s",a);
sscanf(a,"%lf",&temp);
sprintf(b,"%.2lf",temp);
for(int j=0;j<strlen(a);j++)
{
if(a[j]!=b[j])
flag=false;
}
if(flag&&temp>=-1000&&temp<=1000)
{
average+=temp;
cnt++;
}
else
{
printf("ERROR: %s is not a legal number\n",a);
}
}
if(cnt==0)
printf("The average of 0 numbers is Undefined");
else
average/=cnt;
if(cnt==1)
printf("The average of %d number is %.2lf",cnt,average);
if(cnt>1)
printf("The average of %d numbers is %.2lf",cnt,average);
system("pause");
return 0;
}
PAT 1108
最新推荐文章于 2021-02-25 23:18:56 发布