关于‘1001.A+B Format (20)’的解题报告
1001.A+B Format(20)
首先要感谢一下指导我github上传问题的小伙伴们,捣腾了一整天我终于摸到了一点门路,真的谢谢你们。
问题描述:
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和a+b的数据落在[-2000000,2000000]区间内,也就是说在输出时,数据最多的情况需要将其分成三组。
- 剩下的问题就是在格式的需要上,每三个数位为一组,这就要求不足三位的情形有时候需要用“0”补齐。
‘A+B Format’代码
#include<stdio.h>
#include<math.h>
int main()
{
int a,b,sum;
scanf("%d%d",&a,&b);
sum=a+b;
if(abs(sum)>=1000000)
printf("%d,%03d,%03d",sum/1000000,abs((sum/1000)%1000),abs(sum%1000));
else if(abs(sum)<1000)
printf("%d",sum);
else
printf("%d,%03d",sum/1000,abs(sum%1000));
return 0;
}
提交记录

回看代码,发现了一些小细节的疏忽。

在纠正了代码里小于等于三个数位的输出格式问题以及分类的区间分界问题以后,提交通过。

附上我的PDF:小豪的pdf
“谢谢观赏”一脸满足的小豪如上说到。
(菜鸡小豪的编程历程还在持续做更中......)
关于‘1001.A+B Format (20)’的解题报告的更多相关文章
- 1001.A+B Format (20)的解题
关于A+B的正确打开方式! 解题思路 gitub 也是研究了很久才学会了本地上传,中间还遇到一些问题,多亏学长的教程跟搜索引擎的帮忙解决啦! 我想还是了解题目的意思是解题的最关键,通过了查词软件跟自身 ...
- 1001. A+B Format (20)的解题思路以及多源代码文件的尝试编写
前言 这几天刚学了多源代码文件的编译,因为想尝试使用一下这种方法,所以想用此编写这次作业的程序.正好可以learning by doing,在做当中学习新知识.(编译器为Dev-C++) github ...
- "1001. A+B Format (20)" 解题报告
Github : git@github.com:Circlecos/object-oriented.git PDF Of Markdown : "1001. A+B Format (20)& ...
- PAT-PAT (Advanced Level) Practise 1001. A+B Format (20) 【二星级】
题目链接:http://www.patest.cn/contests/pat-a-practise/1001 题面: 1001. A+B Format (20) Calculate a + b and ...
- 1001. A+B Format (20) (%0nd)
1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate ...
- 1001.A+B Format (20)代码自查(补足版)
1001.A+B Format (20)代码自查(补足版) 谢谢畅畅酱的提醒,发现了代码中的不足,把变量名更改成更合理的名字,并且把注释也换成英文啦! 栋哥提供的代码自查的方式也帮助了我发现很多代码中 ...
- PAT 甲级 1001 A+B Format (20)(20 分)
1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the dig ...
- PAT 甲级1001 A+B Format (20)(C++ -思路)
1001 A+B Format (20)(20 分) Calculate a + b and output the sum in standard format -- that is, the dig ...
- PAT甲 1001. A+B Format (20) 2016-09-09 22:47 25人阅读 评论(0) 收藏
1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate ...
随机推荐
- PHP+Ajax+plupload无刷新上传头像代码
很简单的一款PHP+Ajax+plupload无刷新上传头像代码,兼容性很好,可以直接拿来用.你可以自定义各种类型的文件.本实例中只能上传"jpg", "png" ...
- [外观] Firemonkey Windows Hint 气球样式
Firemonkey 在 Windows 平台下的 Hint 默认为距形,有些单调,现在只要加入一行代码,就可以有气球箭头样式的 Hint. 修改代码: 请将 FMX.Controls.Win.pas ...
- C语言学习记录_2019.02.09
打印字符串:%s--------printf("%s","abcd"); 打印字符串数组中某一位:%c--------printf("%c" ...
- R语言数据结构一
R是面向对象的语言,它跟其他编程语言的数据类型差不多,有四种,分别为:数值型,复数型,逻辑性和字符型 数值型:即数字,分为整数型和双精度型.数字可以用科学技术法表示,形式为Xe+m,意为x乘10的m次 ...
- 【转载】COM 组件设计与应用(四)——简单调用组件
原文:http://vckbase.com/index.php/wv/1211.html 一.前言 同志们.朋友们.各位领导,大家好. VCKBASE 不得了, 网友众多文章好. 组件设计怎么学? 知 ...
- 4515: [Sdoi2016]游戏
4515: [Sdoi2016]游戏 链接 分析: 树链剖分 + 超哥线段树.注意细节. 代码: #include<cstdio> #include<algorithm> #i ...
- OpenStack入门篇(二十二)之实现阿里云VPC的SDN网络
1.修改/etc/neutron/neutron.conf配置 [root@linux-node1 ~]# vim /etc/neutron/neutron.conf [defalut] ... co ...
- LBP人脸识别的python实现
这几天看了看LBP及其人脸识别的流程,并在网络上搜相应的python代码,有,但代码质量不好,于是自己就重新写了下,对于att_faces数据集的识别率能达到95.0%~99.0%(40种类型,每种随 ...
- JavaScript流程控制及函数
1 流程控制 1.1 条件语句 分支结构 单向分支 if (条件表达式) { code...} 双向分支 if (条件表达式){ } else { } <!DOCTYPE html& ...
- python连接数据库问题小结
在使用python连接数据库的时候遇到了这个问题: 大概意思就是在django的setting.py中配置的用户名和密码报错. 主要就是修改setting.py的配置 其中在里边的name和user项 ...