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. getSqlMapClientTemplate().insert()方法的返回值问题

    insert方法的返回值     今天碰到一个问题,就是关于ibatis的insert方法的返回值的问题.在网上找了很多例子,自己也亲自试了一下. 最后得出结论:insert方法返回的是在表中插入记录 ...

  2. dll ocx cab IE 自动安装

    我们打开淘宝等网站时,IE浏览器会提示安装空间,这个控件便是用于对用户名密码进行加密的ActiveX控件.如何在我们的站点上安装如此控件,让用户可以通过简单的点击便可方便使用我们的空间呢? 下面是如何 ...

  3. Linux笔记-Makefile伪指令解析

    本文是我在博客里面找到的,觉得对makefile的伪指令介绍得非常详细了!也提到了伪指令为何要用.PHONY:来声明!希望我的这篇转过来的文章能够帮助大家理解makefile的伪指令! 我的理解: 拿 ...

  4. 控件--spinner(列表选项框)

    1. 关键点 1). Spinner的菜单显示方式 它有两种显示形式,一种是下拉菜单,一种是弹出框,菜单显示形式是spinnerMode属性决定的: android:spinnerMode=" ...

  5. CodeIgniter 目录结构详解

    1. myshop 2. |-----system 框架程序目录 3. |-----core 框架的核心程序 4. |-----CodeIgniter.php 引导性文件 5. |-----Commo ...

  6. github提交代码不用输入账号密码的解决方案

    1.在命令行输入命令: git config --global credential.helper store 这一步会在用户目录下的.gitconfig文件最后添加: [credential] he ...

  7. hdu 1075 What Are You Talking About 字典树模板

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  8. POJ 1258(最小生成树+知识)

    用kruskal算法,利用w[i]给r[i]间接排序,从而r[i]可以按照边大小保存序号,同时要判断是否在一个集合里面 #include <cstdio> #include <ios ...

  9. 使用admin lte 碰到访问Google字体的问题

    下载了admin lte 的模板,运行的时候,发现很慢,看了一下console,发现adminlte.css里有import google的字体文件,众所周知的原因,无法访问,所以网页很慢,没办法,只 ...

  10. js-99乘法表的练习

    <html> <head> <title>World</title> <style type="text/css"> & ...