#include<bits/stdc++.h>
using namespace std;
int main(){
int n,num=0;
cin>>n;
double sum=0.0;
char a[50],b[50];
while(n--){
scanf("%s",a);
double k=0.0;
sscanf(a,"%lf",&k);
sprintf(b,"%.2f",k);
bool flag=true;
for(int i=0;i<strlen(a);i++){
if(a[i]!=b[i])
flag=false;
}
if(!flag||k>1000||k<-1000)
printf("ERROR: %s is not a legal number\n",a);
else{
num++;
sum+=k;
}
}
if(num==0)
printf("The average of 0 numbers is Undefined");
else if(num==1)
printf("The average of 1 number is %.2f",sum);
else
printf("The average of %d numbers is %.2f",num,sum/num);
return 0;
}
PAT甲级1108,字符串
最新推荐文章于 2021-02-18 14:54:12 发布