关于‘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 ...
随机推荐
- Deepin15.8系统下安装QorIQ Linux SDK v2.0 yocto成功完美运行的随笔
2019.2.17日:最终安装成功,完美解决! 2019.2.16日:最终安装未成功,但是过程中排除 了几个bug,前进了几步,仅供参考. 写在最前面,yocto安装是有系统要求的,Deepin 15 ...
- Java基础—集合
一.概述 Java中的集合框架主要分为两大派别:Collection 和 Map —— 位于util包下 类的基础关系图如下(图片来自百度) 常用: List——有序可重复 Set——无序不可重复 M ...
- 第五周 加分题-mybash的实现
第五周 加分题-mybash的实现 使用fork,exec,wait实现mybash 产品代码 #include <stdio.h> #include <stdlib.h> # ...
- 20155327实验一 Java开发环境的熟悉
20155327实验一 Java开发环境的熟悉 实验内容 1.使用JDK编译.运行简单的java程序 2.使用IDEA编辑.编译.运行.调试java程序 实验步骤 1.使用JDK编译.运行简单的jav ...
- Java List添加元素
import java.util.ArrayList; public class Test { public static void main(String[] args) { ...
- c++ 字符串和字符串库函数
//有2个字符串定义如下: //char s1[38]="www.yjxsoft"; //char s2[]=".com"; //请编写一段代码,把字符串s2追 ...
- jQuery学习-属性选择器
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 【LG3249】[HNOI2016]矿区
[LG3249][HNOI2016]矿区 题面 洛谷 题解 先平面图转对偶图, 建好了对偶图之后随意拿出一个生成树,以无边界的范围为根. 无边界的范围很好求,用叉积算出有向面积时,算出来是负数的就是无 ...
- metasploit-端口扫描
大体可以分为两种方式: 1.调用nmap进行端口扫描 msfconsole nmap -v -sV www.cstc.org.cn 扫描结果(端口开放情况以及目标服务操作系统相关操作信息) PORT ...
- P4047 [JSOI2010]部落划分
显然二分答案\(mid\),然后距离\(\leq mid\)的点对只能放在一个部落里.然后可以并查集\(O(n^2)\)算出有多少个部落. // luogu-judger-enable-o2 #inc ...