简单模拟。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; char s[];
int n;
int num,num2,pos; bool f()
{
int p=;
for(int i=;s[i];i++)
{
if(s[i]>=''&&s[i]<='') continue;
else if(i==&&s[i]=='-') continue;
else if(s[i]=='.') {p++; continue;}
else return ;
} if(p>) return ; pos=strlen(s);
for(int i=;s[i];i++) if(s[i]=='.') pos=i; int hh=strlen(s)-pos-;
if(hh>) return ; num=;
for(int i=;i<pos;i++)
{
if(s[i]>=''&&s[i]<='')
num=num*+s[i]-'';
if(num>) return ;
}
if(num>) return ; num2=;
for(int i=pos+;s[i];i++)
num2=num2*+s[i]-''; double a=1.0*num+num2/(pow(10.0,strlen(s)-pos-));
if(a>1000.0) return ; return ;
} int main()
{
scanf("%d",&n);
double sum=;
int geshu=;
for(int i=;i<=n;i++)
{
scanf("%s",s);
if(f()==)
printf("ERROR: %s is not a legal number\n",s);
else
{
double a=;
a=1.0*num+num2/(pow(10.0,strlen(s)-pos-));
if(s[]=='-') a=-a;
sum=sum+a;
geshu++;
}
}
if(geshu==)
printf("The average of 1 number is %.2lf\n",sum);
else if(geshu==)
printf("The average of 0 numbers is Undefined\n");
else
printf("The average of %d numbers is %.2lf\n",geshu,sum/geshu);
return ;
}

PAT (Advanced Level) 1108. Finding Average (20)的更多相关文章

  1. 【PAT甲级】1108 Finding Average (20分)

    题意: 输入一个正整数N(<=100),接着输入一行N组字符串,表示一个数字,如果这个数字大于1000或者小于1000或者小数点后超过两位或者压根不是数字均为非法,计算合法数字的平均数. tri ...

  2. PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...

  3. PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...

  4. PAT Advanced 1108 Finding Average (20 分)

    The basic task is simple: given N real numbers, you are supposed to calculate their average. But wha ...

  5. PAT甲级——1108.Finding Average (20分)

    The basic task is simple: given N real numbers, you are supposed to calculate their average. But wha ...

  6. PAT甲题题解-1108. Finding Average (20)-字符串处理

    求给出数的平均数,当然有些是不符合格式的,要输出该数不是合法的. 这里我写了函数来判断是否符合题目要求的数字,有点麻烦. #include <iostream> #include < ...

  7. Day 007:PAT训练--1108 Finding Average (20 分)

    话不多说: 该题要求将给定的所有数分为两类,其中这两类的个数差距最小,且这两类分别的和差距最大. 可以发现,针对第一个要求,个数差距最小,当给定个数为偶数时,二分即差距为0,最小:若给定个数为奇数时, ...

  8. PAT (Advanced Level) Practice 1035 Password (20 分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  9. 【PAT Advanced Level】1008. Elevator (20)

    没什么难的,简单模拟题 #include <iostream> using namespace std; int main() { int num; cin>>num; int ...

随机推荐

  1. javascript焦点图自动缓冲滚动

    html中调用的js库,之前的随笔中有写,就不细说了,不明白的可以留言给我 <!DOCTYPE html> <html> <head> <meta chars ...

  2. 数据库 mysql 语句

    LAMP: Linux系统 A阿帕奇服务器 Mysql数据库 Php语言 mysql:常用代码 create table CeShi1( Uid varchar(50) primary key, Pw ...

  3. drupal7 开发block

    在自己开发的模块的module文件中,实现两个钩子:hook_block_info()和hook_block_view() function journal_block_info() { $block ...

  4. Tenured 区并发垃圾回收器CMS介绍

    当使用CMS收集器时,当开始进行收集时,old代的收集过程如下所示:1,首先jvm根据-XX:CMSInitiatingOccupancyFraction,-XX:+UseCMSInitiatingO ...

  5. ACM心路

    又到了夏天了,这个季节最容易发春,最近上课效率怎么这么低,哎,,别发春了,好好学习,天天向上,现在想妹子,都是空想,没有什么实际意义,纯属浪费时间,浪费生命,不如节约点时间到学习上,不学无术,到嘴边的 ...

  6. Mysql 本地计算机无法启动 mysql 服务 错误 1067:进程意外终

    1.重装后启动mysql服务,提示 本地计算机无法启动 mysql 服务 错误 1067:进程意外终止. 2.查看mysql根目录下有一 计算机名.err 打开一看全是英文的错误提示: 3.根据其中的 ...

  7. isset() 与 empty() 的区别

    PHP的isset()函数 一般用来检测变量是否设置 格式:bool isset ( mixed var [, mixed var [, ...]] ) 功能:检测变量是否设置 返回值: 若变量不存在 ...

  8. js 数组切换图片

    <html> <head> <meta charset="utf-8" /> <title></title> <s ...

  9. json 数组 对象 xml 之间转换(待补充)

    json 数组  xml 对象   之间转换(待补充) 1 把对象的类型或者数组转换成字符串类型(或者更确切的说是json类型的). 此处参考链接http://www.jb51.net/article ...

  10. jsp第1讲(上集)

    jsp讲解框架 (一)Java EE核心十三种技术介绍 (二)Java EE程序员修炼成精的法门 (三)jsp版本的用户管理系统演示 (四)jsp概述 (五)jsp的运行原理 (六)jsp版的计算器 ...