对1001. A+B Format (20)的描述
Github仓库的链接
https://github.com/deepYY/object-oriented/blob/master/A-B-Format/A.B.Format.c
解题思路:
输入a,b,并求a与b 之和c
将c分为没有逗号和有1个逗号和有两个逗号
用除和求余的方法求c的各个三位数,在各个三位数之间加上逗号并输出
bug的发现和修改过程:
- 问题1:调试的过程中,逗号后面还存在负数

#include<stdio.h>
int main()
{
int a, b, c;
scanf("%d %d",&a,&b);
c = a + b;
if (c >= 1000000 || c <= -1000000) {printf("%d,%d,%d", c / 1000000, (c / 1000) % 1000, c % 1000);}
else if (c >= 1000 || c <= -1000) {printf("%d,%d", c / 1000, c % 1000); }
else {printf("%d", c);}
return 0;
}
- 修改:c为负数取余时余数也为负数,我就修改先将c取正在输出数之前加个负号
- 问题2:输出正数时,位数少了许多,有些零不见了

#include<stdio.h>
int main()
{
int a, b, c;
scanf("%d %d",&a,&b);
c = a + b;
if (c < 0){
printf("-");
c = -c; }
if (c >= 1000000) {printf("%d,%d,%d", c / 1000000, (c / 1000) % 1000, c % 1000);}
else if (c >= 1000) {printf("%d,%d", c / 1000, c % 1000); }
else {printf("%d", c);}
return 0;
}
- 修改:输出时加上%03d 在不足三位数时补上零
PAT的截图

对1001. A+B Format (20)的描述的更多相关文章
- 1001.A+B Format (20)解题描述
1. 作业链接 2. 解题的思路过程 首先这是道简单的计算题,要求计算a+b的值. 看初值条件,将a和b的取值限制在一个区间内. 本题难点和重点是如何把输出值形成题目要求的格式. 因为负数可通过在前面 ...
- 关于‘1001.A+B Format (20)’的解题报告
1001.A+B Format(20) 首先要感谢一下指导我github上传问题的小伙伴们,捣腾了一整天我终于摸到了一点门路,真的谢谢你们. 小豪的github 问题描述: Calculate a + ...
- "1001. A+B Format (20)" 解题报告
Github : git@github.com:Circlecos/object-oriented.git PDF Of Markdown : "1001. A+B Format (20)& ...
- 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 ...
- 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 ...
- 【PAT】1001. A+B Format (20)
1001. A+B Format (20) Calculate a + b and output the sum in standard format -- that is, the digits m ...
随机推荐
- kmp java implement--转
http://cs.nyu.edu/~yap/classes/basic/progs/patternMatching/KMP.java /** * @file KMP.java * @synopsis ...
- i.mx6 Android5.1.1 初始化流程之init进程(未完成)
概述: 接在i.mx6 Android5.1.1 初始化流程之框架之后 参考资料:http://blog.csdn.net/mr_raptor/article/category/799879 相关源码 ...
- 应输入 #endregion 指令报错的排查技巧
VS2010中错误排查的一个小技巧,欢迎大家吐槽: 错误 9 应输入 #endregion 指令sses.cs 3778 2 xxx.xx 这个错很明显,是缺少#endr ...
- SQL Serever学习16——索引,触发器,数据库维护
sqlserver2014数据库应用技术 <清华大学出版社> 索引 这是一个很重要的概念,我们知道数据在计算机中其实是分页存储的,就像是单词存在字典中一样 数据库索引可以帮助我们快速定位数 ...
- .NET中的集合-ArrayList1
集合命名空间: using.System.Collections;(非泛型集合) using.System.Collections.Genneric(泛型集合) 常用的集合 1.“类似数组”集合:Ar ...
- C#可选参数、命名参数、参数数组
学习了C#4.0的新特性:可选参数.命名参数.参数数组. 1.可选参数,是指给方法的特定参数指定默认值,在调用方法时可以省略掉这些参数. 但要注意: (1)可选参数不能为参数列表的第1个参数,必须位于 ...
- ssm项目快速搭建(注解)
dao层配置 dao层配置注意事项: 1.Mapper.xml 文件中的 namespace 与 mapper 接口的类路径相同 2.Mapper.xml 接口方法名和 Mapper.xml 中定义的 ...
- 原生canvas写的飞机游戏
一个原生canvas写的飞机游戏,实用性不大,主要用于熟悉canvas的一些熟悉用法. 项目地址:https://github.com/BothEyes1993/canvas_game
- 关于Bootstrap的悬浮窗口(popover)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- ButterKnife 初体验
ButterKnife 环境搭建 在project的build.gradle文件中添加依赖的插件 //ButterKnife 的插件 // classpath 'com.jakewharton:but ...