1001.A+B Format(20)

首先要感谢一下指导我github上传问题的小伙伴们,捣腾了一整天我终于摸到了一点门路,真的谢谢你们。

小豪的github

问题描述:

Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).

  • Input

    Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.

  • Output

    For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.

  • Sample Input

    -1000000 9

  • Sample Output

    -999,991

解题思路

  • 刚开始拿到题目的时候,我犹豫了一下键入数据的正负号问题,后来想想其实并不需要对键入数据的正负号进行讨论,所以只需要求和运算就好。
  • 接着看到输出数据的类型,不难联想到美式计数法,输出的数据以三个数位为一组,中间通过使用“,”相隔开。
  • a、b和a+b的数据落在[-2000000,2000000]区间内,也就是说在输出时,数据最多的情况需要将其分成三组。
  • 剩下的问题就是在格式的需要上,每三个数位为一组,这就要求不足三位的情形有时候需要用“0”补齐。

‘A+B Format’代码

#include<stdio.h>
#include<math.h>
int main()
{
int a,b,sum;
scanf("%d%d",&a,&b);
sum=a+b;
if(abs(sum)>=1000000)
printf("%d,%03d,%03d",sum/1000000,abs((sum/1000)%1000),abs(sum%1000));
else if(abs(sum)<1000)
printf("%d",sum);
else
printf("%d,%03d",sum/1000,abs(sum%1000));
return 0;
}

提交记录

回看代码,发现了一些小细节的疏忽。

在纠正了代码里小于等于三个数位的输出格式问题以及分类的区间分界问题以后,提交通过。

附上我的PDF:小豪的pdf

“谢谢观赏”一脸满足的小豪如上说到。

(菜鸡小豪的编程历程还在持续做更中......)

关于‘1001.A+B Format (20)’的解题报告的更多相关文章

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

    关于A+B的正确打开方式! 解题思路 gitub 也是研究了很久才学会了本地上传,中间还遇到一些问题,多亏学长的教程跟搜索引擎的帮忙解决啦! 我想还是了解题目的意思是解题的最关键,通过了查词软件跟自身 ...

  2. 1001. A+B Format (20)的解题思路以及多源代码文件的尝试编写

    前言 这几天刚学了多源代码文件的编译,因为想尝试使用一下这种方法,所以想用此编写这次作业的程序.正好可以learning by doing,在做当中学习新知识.(编译器为Dev-C++) github ...

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

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

  4. PAT-PAT (Advanced Level) Practise 1001. A+B Format (20) 【二星级】

    题目链接:http://www.patest.cn/contests/pat-a-practise/1001 题面: 1001. A+B Format (20) Calculate a + b and ...

  5. 1001. A+B Format (20) (%0nd)

    1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate ...

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

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

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

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

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

随机推荐

  1. BZOJ2194: 快速傅立叶之二(NTT,卷积)

    Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1776  Solved: 1055[Submit][Status][Discuss] Descript ...

  2. Python2.7在Windows下CMD编码为65001/utf-8时print报错[Errno 0]/[Errno 2]

    使用python2.7处理unicode的字符串,环境变量已设置PYTHONIOENCODING为utf-8,cmd编码为utf-8时print unicode字符串会报错[Errno 0]或[Err ...

  3. flex拖动图片

    <?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx="htt ...

  4. tomcat软连接的使用

    软连接说白了就是一个映射.可以映射文件,也可以映射目录.linux和windows都可以做软连接,加入现在把文件A.txt做软连接到B.txt: linux命令如下: ln -s A.txt B.tx ...

  5. PPAS的MTK tool 工具使用说明

    磨砺技术珠矶,践行数据之道,追求卓越价值 回到上一级页面: PostgreSQL基础知识与基本操作索引页     回到顶级页面:PostgreSQL索引页 [作者 高健@博客园  luckyjackg ...

  6. 字符串Hash/树Hash学习笔记

    哈希 Tags:字符串 作业部落 评论地址 一.概述 百度百科: 散列表(Hash table/哈希表),是根据关键码值(Key value)而直接进行访问的数据结构. 哈希表常用于比较两个字符串是否 ...

  7. VirtualBOX启动错误the vm session was closed before any attempt to power it on解决办法

    昨天晚上笔记本休眠后,今天早上启动vm时,报错了. 点击详细启动错误:the vm session was closed before any attempt topower it on. 解决办法: ...

  8. 4552: [Tjoi2016&Heoi2016]排序

    4552: [Tjoi2016&Heoi2016]排序 链接 分析: 因为只询问一次,所以考虑二分这个数.显然是没有单调性的,但是我们可以二分所有大于等于mid的数中,是否有满足条件的x(而不 ...

  9. Kubernetes学习之路(五)之Flannel网络二进制部署和测试

    一.K8S的ip地址 Node IP:节点设备的IP,如物理机,虚拟机等容器宿主的实际IP. Pod IP:Pod的IP地址,是根据docker0网络IP段进行分配的. Cluster IP:Serv ...

  10. P4438 [HNOI/AHOI2018]道路

    辣稽题目 毁我青春 耗我钱财. 设\(f[x][i][j]\)为从1号点走到x点经过i条公路j条铁路,子树的最小代价. \(f[leaf][i][j]=(A+i)(B+j)C\) \(f[x][i][ ...