PAT----1001. A+B Format (20)解题过程
1001. A+B Format (20)
github链接
时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
Calculate a + b and output the sum in standard format -- that is,the digits must be separated into groups of three by commas(unless there are less than four digits).
Input
Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.
Output
For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.
Sample Input
-1000000 9
Sample Output
-999,991
题目大意
输入整数 a , b(-1000000 <= a, b <= 1000000);计算a,b的和;
重点是:结果要按照“三位分级法”输出。(e.g -999,991 )
解题思路
第一次读题后首先想到的是数组和字符串,但是实现起来有难度(如果用c++可能会好一些,但是我还没学完!),而且就算能用C语言实现,也很繁琐。所以最后还是决定用一些最基础的算法去解决这道题。
- 这道题主要考的是 三位分级法,而且-2000000<= sum <= 2000000;所以我们可以分类讨论:(设 c 为sum的绝对值,因为结果有负数,所以要用绝对值进行分类讨论)
- C<1000 (直接输出sum)
- 1000<= C <1000000 (有一个逗号)
- C>=1000000 (有两个逗号)
最后,每种情况对应一种输出方式;然后输出结果。
我对照着编译运行的结果又重新检查了一遍,发现代码中输出格式出错,逗号之后的数位要用0补齐;并且,中间三位数的算法出错!
在修改完代码之后,成功 AC!
pdf版本
PAT----1001. A+B Format (20)解题过程的更多相关文章
- "1001. A+B Format (20)" 解题报告
Github : git@github.com:Circlecos/object-oriented.git PDF Of Markdown : "1001. A+B Format (20)& ...
- 1001.A+B Format (20)解题描述
1. 作业链接 2. 解题的思路过程 首先这是道简单的计算题,要求计算a+b的值. 看初值条件,将a和b的取值限制在一个区间内. 本题难点和重点是如何把输出值形成题目要求的格式. 因为负数可通过在前面 ...
- 1001.A+B Format (20) 解题
代码入口(https://github.com/NSDie/object-oriented) 这题的解题思路我有两个: 第一个是两个数字相加然后判断位数,因为题目限制了范围1000000的绝对值以内嘛 ...
- (2016.2.2)1001.A+B Format (20)解题思路
https://github.com/UNWILL2LOSE/object-oriented 解题思路 目标: *首先运算要求实现输入2个数后,输出类似于银行的支票上的带分隔符规则的数字. 代码实现思 ...
- PAT 1001 A+B Format (20分) to_string()
题目 Calculate a+b and output the sum in standard format -- that is, the digits must be separated into ...
- PAT 1001 A+B Format (20 point(s))
题目: 我一开始的思路是: 用math.h中的log10函数来计算位数(不建议这么做,因为会很慢,而且会出一点别的问题): 用pow函数根据要插入分号的位置来拆分a+b成一个个数字(例如res / p ...
- PAT 1001. A+B Format 解题
GitHub PDF 1001. A+B Format (20) Calculate a + b and output the sum in standard format -- that is, t ...
- 关于‘1001.A+B Format (20)’的解题报告
1001.A+B Format(20) 首先要感谢一下指导我github上传问题的小伙伴们,捣腾了一整天我终于摸到了一点门路,真的谢谢你们. 小豪的github 问题描述: Calculate a + ...
- PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642
PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642 题目描述: Calculate a+b and output the sum i ...
随机推荐
- Python os.md
os 便携式访问操作系统的特定功能.os模块提供了对特定平台模块(如posix, nt, mac)的封装, 函数提供的api在很多平台上都可以相同使用, 所以使用os模块会变得很方便. 但不是所有函数 ...
- HTTP协议请求方式: 中GET、POST和HEAD的介绍_孤帆一叶
HTTP协议中GET.POST和HEAD的介绍 2008-05-10 14:15 GET: 请求指定的页面信息,并返回实体主体.HEAD: 只请求页面的首部.POST: 请求服务器接受所指定的文档作为 ...
- -bash: fork: retry: Resource temporarily unavailable;centos6.5
Last login: Wed Jun 18 14:04:11 2014 from 1.1.1.135 -bash: fork: retry: Resource temporarily unavail ...
- OpenCV——staturate_cast、掩模操作
saturate_cast<>()模板函数,用于溢出保护 //大致的原理如下 ) data=; elseif(data>) data=; 掩模操作:https://blog.csdn ...
- 无oracle客户端仅用plsql连接远程oracle
1.在安装ORACLE服务器的机器上搜索下列文件,oci.dllocijdbc10.dllociw32.dllorannzsbb10.dlloraocci10.dlloraociei10.dllsql ...
- day38
今日内容: 1.认识数据库 2.修改默认密码 3.常用操作指令 1.认识数据库 什么是MYSQL? 是一个关系型数据库管理系统,基于socket编写的C/S架构的软件 什么是数据库? 数据:用于记录事 ...
- WPF bind baidu Image
as there baidu image has protect refer from other site to use. need download i use request header a ...
- Mybatis初步详细配置
1.Mybatis所需包 下载地址:https://github.com/mybatis/mybatis-3/releases,其中log4j是日志包,mysql是数据库所需包,需自行下载 2.项目结 ...
- Luogu P1983 车站分级
(一周没写过随笔了) 这道题有坑! 看到题目,发现这么明显(??)的要求顺序,还有什么想法,拓扑! 将每条路范围内等级大于等于它的点(不能重复(坑点1))和它连一条边,注意起点终点都要有(坑点2),然 ...
- helloworld讲解cocos2d-x的编程思路与要点
用helloworld讲解cocos2d-x的编程思路与要点 本文以cocos2d-x的helloworld为例,讲解cocos2d-x引擎的特点和要点,2.2为了展示新功能,把包括屏幕自适应在内的新 ...