1001. A+B Format (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

解题思路:这里主要是注意一下补0的问题

     %nd:n代表的是列宽长度。

(1)%-nd   -  代表的是左对齐。

(2)%nd       代表的是右对齐。

(3)%0nd   0(数字零)代表的是不足n位长度的左补齐0。

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

1001. A+B Format (20) (%0nd)的更多相关文章

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

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

  3. 1001.A+B Format (20)(思路,bug发现及其修改,提交记录)

    https://github.com/031502316a/object-oriented/tree/master/1001 ---恢复内容开始--- 1.解题思路 一开始见到题目时,感觉难的就是输出 ...

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

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

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

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

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

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

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

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

随机推荐

  1. 随机带权选取文件中一行 分类: linux c/c++ 2014-06-02 00:11 344人阅读 评论(0) 收藏

    本程序实现从文件中随即选取一行,每行被选中的概率与改行长度成正比. 程序用一次遍历,实现带权随机选取. 算法:假设第i行权重wi(i=1...n).读取到文件第i行时,以概率wi/(w1+w2+... ...

  2. 2、IO流的分类和IO流体系

  3. 转-UIButton定义和设置圆角

    //login button // .h 中定义 UIButton *_loginBtn; @property (strong,nonatomic)UIButton *loginBtn; // .m ...

  4. 转 PHP in_array() 函数

    实例 在数组中搜索值 "Glenn" ,并输出一些文本: <?php $people = array("Bill", "Steve", ...

  5. unix shell 解析 1

    ---- shell 1 testdb3:/home/oracle [pprod] >more /home/oracle/utility/macro/tns_log_back_12c.sh #! ...

  6. AJPFX解析成员变量和局部变量

    成员变量和局部变量 3.1.成员变量和局部变量 A:在类中的位置不同         * 成员变量:在类中方法外         * 局部变量:在方法定义中或者方法声明上 B:在内存中的位置不同   ...

  7. Elasticsearch--集群管理_再平衡&预热

    目录 控制集群的再平衡 再平衡 集群的就绪 集群再平衡设置 控制再平衡何时开始 控制同时在节点移动的分片数量 控制单个节点上同时初始化的分片数量 控制单个节点上同时初始化的主分片数量 控制分配的分片类 ...

  8. 501在全志r16平台tinav3.0系统下调通pwm1的10KHZ波形

    501在全志r16平台tinav3.0系统下调通pwm1的10KHZ波形 2018/10/19 19:52 版本:V1.0 开发板:SC3817R SDK:tina v3.0 1.01原始编译全志r1 ...

  9. React 实践心得:react-redux 之 connect 方法详解

    Redux 是「React 全家桶」中极为重要的一员,它试图为 React 应用提供「可预测化的状态管理」机制. Redux 本身足够简单,除了 React,它还能够支持其他界面框架.所以如果要将 R ...

  10. 【C++】模板简述(六):总结

    1.模板技术是泛型编程的基础.([C++]模板简述(一):模板的引入) 2.模板被编译两次,因而给分离编译造成一些麻烦.([C++]模板简述(二):函数模板.[C++]模板简述(四):模板为什么不支持 ...