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. 微电子中的die-to-die和within-die

    工艺制造中lot指按某种方式生成的硅柱状体,将这些lot切成薄片就称为wafer,wafer是进行集成电路制造的基板,一般以直径来区分,8寸.10寸,12寸等,或者以毫米来区分.直径越大材料的利用率越 ...

  2. IE7,8纯css实现圆角效果

    众所周知,IE7,8不支持border-radius效果.但我们同样有办法用css实现这个效果,方法就是用border来模拟. <!DOCTYPE html> <html lang= ...

  3. WPF的MediaElement指定Source无法播放问题解决

    最近学wpf,在使用 MediaElement 指定 Source 进行视频播放时,在源码界面可以正常显示,但运行时控件显示空白. 源码界面如下图:(可正常显示) 运行后如下图所示:(控件位置显示空白 ...

  4. 面向对象(基础oop)之属性与构造函数

    大家好,我叫李京阳,,很高兴认识大家,之所以我想开一个自己的博客,就是来把自己所了解的知识点通过自己的话写一下,希望被博客园的朋友们点评和一起讨论一下,也希望从博客园中多认识一些软件开发人员!现在我开 ...

  5. 六、yarn运行模式

    简介 spark的yarn运行模式根据Driver在集群中的位置分成两种: 1)yarn-client 客户端模式 2)yarn-cluster 集群模式 yarn模式和standalone模式不同, ...

  6. 分析解决 spring quartz 中出现的执行两次问题

    1. 问题描述 在开发询盘功能时,遇到一个需求,就是后台定时任务执行用电施工业务的工单下发. 使用的技术是 spring quartz,因为其他应用有先例,配置quartz 完成后,先写了一个 hel ...

  7. 文件下载(Servlet/Struts2)

    文件上传(Servlet/Struts2/SpringMVC)的链接:http://www.cnblogs.com/ghq120/p/8312944.html 文件下载 Servlet实现 目录结构 ...

  8. 理解webpack4.splitChunks之chunks

    上回说到按照默认的splitChunks配置,入口里面的第三方依赖没有打包出来,这个是因为chunks属性的原因,下面我们就介绍chunks属性的意义和用法. chunks的含义是拆分模块的范围,它有 ...

  9. Drupal7配置简洁URL(Clear URL)

    参考:Apache Rewrite url重定向功能的简单配置 这两天折腾死了 首先说一下我的环境: Aache2.4.25-x64-vc14-r1;php-7.0.19-Win32-VC14-x64 ...

  10. 浅谈 Underscore.js 中 _.throttle 和 _.debounce 的差异[转]

    看的文章来自: https://blog.coding.net/blog/the-difference-between-throttle-and-debounce-in-underscorejs 使用 ...