对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 ...
随机推荐
- redis系统和通用函数
construct函数: 用来创建一个redis客户端. redis = new Redis(); connect函数:连接到一个redis实例. 参数如下: host:字符串类型 可以使一个HO ...
- redis数据类型(五)set类型
一. set类型 set是无序集合,最大可以包含(2 的 32 次方-1)个元素. set 的是通过 hash table 实现的,所以添加,删除,查找的复杂度都是 O(1). hash table ...
- 大数据sql引擎
Hive:把sql解析后用MapReduce跑 SparkSQL:把sql解析后用Spark跑,比hive快点 Phoenix:一个绕过了MapReduce运行在HBase上的SQL框架 Drill/ ...
- 如何封装一个Cookie库
由Cookie详解我们已经了解到了Cookie是为了实现有状态的基于HTTP协议的应用而存在的.一个Cookie的由以下几个部分组成: //设置cookie的格式和Set-Cookie头中使用的格式一 ...
- 从零开始学JAVA(08)-使用SpringMVC4 Restful 风格引用静态文件 css/js/png
在写完helloworld后想给网页加点样式(*.css),结果怎么也显示不了,百度了很多种方法后试行尝试,试验成功并记录下来,方便以后查看. 时隔两年,继续学习JAVA,太久没学了,忘记得差不多,还 ...
- [java] byte不能直接相加
以下赋值语句将产生一个编译错误,原因是赋值运算符右侧的算术表达式在默认情况下的计算结果为 int 类型. // Error: conversion from int to byte:byte z = ...
- ef——存储过程
数据库中存在存储过程GetCategory: ALTER proc [dbo].[GetCategory] @cid int as begin select * from Categories w ...
- MongoDB基本用法(增删改高级查询、mapreduce)
TestCase.java package com.wujintao.mongo; import java.net.UnknownHostException; import java.util.Arr ...
- js array copy method
//浅拷贝: let arr=[1,2,3,4] let arr2=arr arr[3]=0 console.log(arr,arr2) //output: (4) [1, 2, 3, 0] (4) ...
- Html5 填表 表单(二) input type 各种输入, 各种用户选择,上传等等泛输入用户交互
<input> 无限制输入 type 限制输入 type = 如下类型 type 后还可以跟一些属性: 如<input type=text max ...