1108 Finding Average (20 point(s))

【信息科学与工程学】【数据科学】数据科学领域——第三篇 数学08 几何学00总篇 编号英文名称中文名称简要说明/归属1Foundations of Geometry几何基础公理化方法, Hilbert《几何基础》2Euclidean Geometry (Synthetic)欧几里得几何(综合法)《几何原本》传统3Analytic Geometry解析几何坐标方法, Descartes, Fermat4Plane Geometry平面几何三角形、圆、共点共线等经典问题5Solid Geometry立体几何三维空间中的图形与度量6Non-Euclidean Geometry非欧几何平行公设不 阅读详情

1108 Finding Average (20 point(s))

The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A legal input is a real number in [−1000,1000] and is accurate up to no more than 2 decimal places. When you calculate the average, those illegal numbers must not be counted in.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤100). Then Nnumbers are given in the next line, separated by one space.

Output Specification:

For each illegal input number, print in a line ERROR: X is not a legal number where X is the input. Then finally print in a line the result: The average of K numbers is Y where K is the number of legal inputs and Y is their average, accurate to 2 decimal places. In case the average cannot be calculated, output Undefined instead of Y. In case K is only 1, output The average of 1 number is Y instead.

Sample Input 1:

7
5 -3.2 aaa 9999 2.3.4 7.123 2.35

Sample Output 1:

ERROR: aaa is not a legal number
ERROR: 9999 is not a legal number
ERROR: 2.3.4 is not a legal number
ERROR: 7.123 is not a legal number
The average of 3 numbers is 1.38

Sample Input 2:

2
aaa -9999

Sample Output 2:

ERROR: aaa is not a legal number
ERROR: -9999 is not a legal number
The average of 0 numbers is Undefined

中等模拟题。

模拟题心得:判断时,要根据限制条件选择给出合法条件还是不合法条件。有时候,难以想到所有完备的不合法条件。

巨坑:当合法数字是1的时候,number(s)不应该取复数! 

#include<iostream>
#include<cstring>
using namespace std;
bool isLegal(string s,double &n){
	n=0;
	bool isNeg = false;
	if(s[0]=='-'){
		isNeg = true;
		s.erase(s.begin());
	}
	bool hasPoint = false;
	int in = 0;
	double p=0;
	int cnt=0;
	for(int i=0;i<s.length();i++){
		if(s[i]>='0'&&s[i]<='9'){
			if(!hasPoint) in=10*in+(s[i]-'0');
			else if(hasPoint&&cnt<2){
				cnt++;
				if(cnt==1) p = 0.1*(s[i]-'0');
				else if(cnt==2) p+=0.01*(s[i]-'0');
			}
			else return false;
		}
		else if(in!=0&&s[i]=='.'&&!hasPoint) hasPoint = true;
		else return false;
	}
	if(isNeg) n = -p-in;
	else n = p+in;
	if(n<=1000.0&&n>=-1000.0) return true;
	else return false;
}
int main(void){
	int N;cin>>N;
	int cnt = 0;double sum = 0;
	string s;double x;
	for(int i=0;i<N;i++){
		cin>>s;
		if(isLegal(s,x)){
			cnt++;
			sum+=x;
		}
		else{
			cout<<"ERROR: "<<s<<" is not a legal number"<<endl;
		}
	}
	if(cnt==1) cout<<"The average of "<<cnt<<" number is ";
	else cout<<"The average of "<<cnt<<" numbers is ";
	
	if(cnt==0) cout<<"Undefined"<<endl;
	else {
		printf("%.2f\n",sum/cnt);
	}
} 

 

【信息科学与工程学】计算机科学与自动化——第六十六篇 算子篇 第一章 通用算子01 多模态数据(图形/图像/文本/语音)中推断人类内在状态、策略、动机和利益的算法算子知识库 编号领域算法/方法算子名称算子的数学方程式/表达复杂度 (示例)关联知识11量子场论正则量子化产生/湮灭算符对易关系: [â_p, â†_q] = δ⁽³⁾(p​ - q)应用于态空间,计算复杂度取决于截断福克空间,粒子数表象,二次量子化12统计力学蒙特卡洛模拟马尔可夫链转移算子T(s → s‘) :满足细致平衡条件 π(s)T(s→s’)=π(s‘)T(s’→s)收敛到平衡分布需 ~O(τ), τ为相关时间细致平衡,Metropolis-Hastings准则,重要性采样13电磁学边界元法单层势/双层势算子 阅读详情

相关推荐

告别硬编码!用Aviator 5.3.3实现动态规则引擎,Spring Boot项目实战教程

本文详细介绍了如何使用Aviator 5.3.3在Spring Boot项目中实现动态规则引擎,告别硬编码。通过Maven依赖集成、规则模型设计、规则执行引擎实现及电商促销系统实战案例,展示了Aviator在动态规则配置中的高效应用,提升业务灵活性和开发效率。

weixin_30329623的博客 446

PAT_甲级_1108 Finding Average (20point(s)) (C++)【字符串处理/sscanf与sprintf/测试点3】

目录 1,题目描述 题目大意 注意 2,思路 3,AC代码 4,解题过程 第一搏 第二搏 第三搏 第四搏 第五搏 1,题目描述 Sample Input 1: 7 5 -3.2 aaa 9999 2.3.4 7.123 2.35 Sample Output 1: ERROR: aaa is not a legal number ERROR: 999...

&再见萤火虫&的博客 502

EtherCAT FOE从站开发实战:SSC工具包实现固件在线升级与文件传输

EtherCAT从站开发中,固件在线升级与文件传输是常见需求。FOE(File Access over EtherCAT)作为邮箱通信协议,在实时总线上提供可靠的文件读写通道,与PDO、DC同步共存。其原理基于SM邮箱和状态机,通过SSC工具包可快速启用。技术价值在于无需拆机即可更新固件、导出日志,提升产线效率。应用场景包括伺服驱动器、IO模块等从站的固件升级与参数配置。本文深入讲解从站侧FOE读写实现、主站调用及工程化建议,助力嵌入式工程师高效开发。

weixin_29169899的博客 128

1108 Finding Average (20分)

The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A legal input is a real...

自己人的博客 259

PyCharm与MicroPython联手:打造高效ESP32开发环境

本文详细介绍了如何使用PyCharm与MicroPython打造高效的ESP32开发环境。通过配置PyCharm插件、刷写MicroPython固件以及实战示例,帮助开发者快速上手嵌入式Python开发,显著提升物联网项目的开发效率。

weixin_29169899的博客 380

手把手教你为STM32设备生成自定义MAC地址(基于芯片ID的5种算法对比)

本文详细介绍了基于STM32芯片ID生成自定义MAC地址的5种算法,包括直接截取、异或折叠、CRC32哈希、自定义混合运算及SHA-256摘要。通过对比分析各算法的计算复杂度、唯一性及适用场景,帮助嵌入式开发者根据项目规模与资源,选择最合适的方案,确保设备MAC地址的唯一性与合规性。

weixin_29170327的博客 528

【PAT】A1108 Finding Average(20)

文章目录A1108 Finding Average (20 point(s))Input Specification:Output Specification:Sample Input 1:Sample Output 1:Sample Input 2:Sample Output 2:CodeAnalyze A1108 Finding Average (20 point(s)) he basic t...

Duke 268

海思Hi3516CV610--SPI NAND Flash移植实战:从手册到驱动的完整适配

本文详细介绍了海思Hi3516CV610芯片上SPI NAND Flash的移植实战,包括从手册解读到驱动适配的完整流程。以GD5F2GM7UEYIGR Flash为例,重点讲解了关键参数确认、模式选择、时序配置以及U-Boot和Linux内核驱动的具体实现步骤,帮助开发者快速完成Flash移植工作。

weixin_29158413的博客 447

1108. Finding Average (20)

1108. Finding Average (20)时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueThe basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it compl...

石前有座桥的博客 303

NMOS管和PMOS管做开关控制电路

NMOS管和PMOS管做开关控制电路

while(1) 3万+

手把手教你用Cadence Virtuoso完成LNA全套仿真:基于SpectreRF手册的实战补充

本文详细指导如何使用Cadence Virtuoso和SpectreRF完成LNA的全套仿真,涵盖噪声仿真、增益压缩、THD分析及双音IP3测量等关键步骤。针对官方手册中的常见问题,提供了12个实战解决方案,包括hbnoise函数选择、双音信号源配置等,帮助工程师高效完成射频IC设计。

weixin_29102619的博客 524

1108 Finding Average (20point(s)) - C语言 PAT 甲级

1. 用 scanf("%8s", str) 处理输入,因为”合法“输入最大字节数为 8 字节,所以一次读取 8 个字节或遇到空字符停止读取 2. double strtod(const char *str, char **endptr) 函数转换字符串为浮点数 3. char *strchr(const char *str, int c) 函数找小数点的位置

有三只土豆 215

从零开始:C#上位机集成YOLO完成摄像头目标追踪(保姆级教程)

新手入门C#上位机+YOLO做摄像头目标追踪,最忌讳的是“只抄代码,不懂逻辑”。这个教程不仅给了完整代码,还把核心原理和踩坑点都讲清楚了,新手跟着走,不仅能跑通demo,还能理解为什么这么写。如果你们在运行时遇到具体问题,比如模型导出失败、代码报错,都可以在评论区留言,我会一一解答。后续也可以出一期工业相机+YOLO目标追踪的教程,帮助大家把demo落地到实际生产中。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1030

1108 Finding Average (20 point(s))

题解 sscanf and sprintf。见sscanf 、sprintf的常见用法 #include&lt;cstdio&gt; #include&lt;iostream&gt; #include&lt;cstring&gt; using namespace std; const int MAXN = 50; char a[MAXN], buf[MAXN]; int n, cnt; ...

徐伯莱 265

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

PTA甲级 1108 Finding Average (20point(s))

强烈推荐,刷PTA的朋友都认识一下柳神–PTA解法大佬 本文由参考于柳神博客写成 柳神的优快云博客,这个可以搜索文章 柳神的个人博客,这个没有广告,但是不能搜索 还有就是非常非常有用的 算法笔记 全名是 算法笔记 上级训练实战指南 //这本都是PTA的题解 算法笔记 PS 今天也要加油鸭 题目原文 The basic task is simple: given N real numbers, you are supposed to calculate their average. But what

Huangpengyu123的博客 286

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

PAT甲级 1108. Finding Average (20)

The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A "legal" input is a re...

moffy_abo的博客 1286

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

1108 Finding Average(20 分)(C++)

The basic task is simple: givenNreal numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. Alegalinput is a real...

qq_41562704的博客 408

1108. Finding Average (20) sscanf() sprintf()

#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;cmath&gt; #include &lt;algorithm&gt; #include &lt;string.h&gt; using namespace std; //sscanf() – 从一个字符串中读进与指定格式相符的数据 //sprintf() – 字符串格式化...

pacmo 235

1108 Finding Average (20)

The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A "legal" input is a re...

ysq96的博客 266

1108 Finding Average(20 分)(cj)

1108 Finding Average(20 分) The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be le...

Cute_jinx的博客 332

1108 Finding Average

1108 Finding Average The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A ...

ssf_cxdm的博客 175

1108. Finding Average (20)[字符串处理]

1. 原题:https://www.patest.cn/contests/pat-a-practise/1108 2.思路: 题意:判断给定的字符串是否有效数字。 思路: 有多个方法。很容易想到对每个字符串进行分析判断,这样也可以, 不过有点麻烦。 另一种方法借助库函数sscanf和sprintf。 sscanf把字符串转换为浮点数tmp,然后用sprintf把tmp转换为字符串

坚不萌 391

Microsoft Office&WPS

本文总结了Office 2016系列软件(Excel、OneNote、Project)的实用操作技巧,重点介绍Excel的各项功能。主要内容包括:1)文档加密与取消加密方法;2)Excel行/列操作(筛选、删除空行、冻结窗格、自动调整列宽);3)格式规范建议(避免空单元格、统一格式等);4)常用公式应用(逻辑判断、进制转换、日期处理、计算函数等);5)特殊操作技巧(数字转字符串、绝对引用、获取列宽行高等)。全文通过表格分类整理各类公式用途与示例,便于快速查询应用。

- 1745

1108 Finding Average(20 分)

1108 Finding Average(20 分) The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be le...

CODER的博客 620
上一篇: 1039 Course List for Student (25 point(s))
下一篇: 1044 Shopping in Mars (25 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值