首页 > 学院 > 开发设计 > 正文

PAT 1108

2019-11-06 07:07:54
字体:
来源:转载
供稿:网友
#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;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表