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)的描述的更多相关文章

  1. 1001.A+B Format (20)解题描述

    1. 作业链接 2. 解题的思路过程 首先这是道简单的计算题,要求计算a+b的值. 看初值条件,将a和b的取值限制在一个区间内. 本题难点和重点是如何把输出值形成题目要求的格式. 因为负数可通过在前面 ...

  2. 关于‘1001.A+B Format (20)’的解题报告

    1001.A+B Format(20) 首先要感谢一下指导我github上传问题的小伙伴们,捣腾了一整天我终于摸到了一点门路,真的谢谢你们. 小豪的github 问题描述: Calculate a + ...

  3. "1001. A+B Format (20)" 解题报告

    Github : git@github.com:Circlecos/object-oriented.git PDF Of Markdown : "1001. A+B Format (20)& ...

  4. 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 ...

  5. 1001.A+B Format (20)代码自查(补足版)

    1001.A+B Format (20)代码自查(补足版) 谢谢畅畅酱的提醒,发现了代码中的不足,把变量名更改成更合理的名字,并且把注释也换成英文啦! 栋哥提供的代码自查的方式也帮助了我发现很多代码中 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 【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 ...

随机推荐

  1. 令狐冲和TCP/IP协议的第三层协议的关系(经典)

    今天突然想起来去看了看我以前在csdn的博客,发现一篇以前一直被奉为经典的文章,哈哈,再转过来和大家看看:              令狐冲十四岁那年进入华山,那年岳琳珊八岁,岳不群白天给两人指点剑法 ...

  2. R语言提取字符串的一部分substring函数

    这个函数提取字符串的一部分. 语法 substring()函数的基本语法是: substring(x,first,last) 以下是所使用的参数的说明: x - 是字符向量输入. first - 是第 ...

  3. ExcelHelper----根据指定样式的数据,生成excel(一个sheet1页)文件流

    /// <summary> /// Excel导出类 /// </summary> public class ExcelHelper { /// <summary> ...

  4. windows 10安装gensim、nltk

    一.安装gensim 1.什么事gensim gensim是一个python的科学库,gensim包含了TF-IDF.随机投影.word2vec和document2vec算法的实现,分层Dirchle ...

  5. 【AppScan】入门工作原理详解

    AppScan,即 AppScan standard edition.其安装在 Windows 操作系统上,可以对网站等 Web 应用进行自动化的应用安全扫描和测试.Rational AppScan( ...

  6. MyBatis中插入并返回主键

    开发过程中经常遇到需要插入一条数据,并且返回这条数据自增的主键,在MyBatis中只需要在mapper中添加keyProperty属性即可 在mapper中添加keyProperty属性 <in ...

  7. unity GUI Layout 组件(全)

    [expand 扩张][fitter 装配工] [envelope 信封,包装] Layout 布局 三种.   Horizontal Layout Group 水平布局 Padding:内边距,单位 ...

  8. android 模拟器无法启动问题

    很早之前就碰到过Android Studio模拟器无法启动的问题,今天终于尝试去解决了下,下面将我解决的方法记录下. 模拟器报错信息为: emulator: ERROR: x86 emulation ...

  9. 撩课-Java每天5道面试题第16天

    111.什么是乐观锁(Optimistic Locking)? 悲观锁,正如其名, 它指的是对数据被外界 包括本系统当前的其他事务, 以及来自外部系统的事务处理 修改持保守态度, 因此,在整个数据处理 ...

  10. 集合框架以及Map(一)

    集合又称容器,编程思想中对其的定义为持有对象 我们在使用集合或者数组时得到最多的异常就是数组下表越界异常 Java.lang.ArrayIndexOutOfBoundsException这篇文章我们不 ...