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 
主要注意两点 :
  1. 输出时要注意逗号,如1000要输出1,000
  2. 要注意后面部分数字的前置0,如1010,要输出1,010,而不是1,10
代码
 1 #include <stdio.h>
 2 int main()
 3 {
 4     int a,b,sum;
 5     int arr[];
 6     while(scanf("%d%d",&a,&b) != EOF){
 7         sum = a+b;
 8         if(sum == ){
 9             printf("0\n");
             break;
         }
         else if(sum < ){
             printf("-");
             sum = sum * -;
         }
         int i = ;
         while(sum){
             arr[i++] = sum % ;
             sum = sum / ;
         }
         printf("%d",arr[--i]);
         for(--i;i >= ;--i){
             printf(",%03d",arr[i]);
         }
         printf("\n");
     }
     return ;
 }

PAT 1001的更多相关文章

  1. PAT 1001 A+B 解题报告

    PAT 1001 A+B 代码链接:传送门 题目链接:传送门 题目简述: 给定两个值a,b: 范围-1000000 <= a, b <= 1000000: 按指定格式输出a+b的结果,例: ...

  2. PAT 1001 害死人不偿命的(3n+1)猜想 (15)(C++&JAVA&Python)

    1001 害死人不偿命的(3n+1)猜想 (15)(15 分) 卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反 ...

  3. PAT 1001. A+B Format 解题

    GitHub PDF 1001. A+B Format (20) Calculate a + b and output the sum in standard format -- that is, t ...

  4. PAT 1001 A+B Fotmat

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

  5. PAT 1001 Format

    problem 1001 A+B Format (20)(20 point(s)) Calculate a + b and output the sum in standard format -- t ...

  6. PAT——1001 害死人不偿命的(3n+1)猜想 (15)

    对给定的任一不超过1000的正整数n,简单地数一下,需要多少步(砍几下)才能得到n=1? 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值. 输出格式:输出从n计算到1需要的步数. 输入样例 ...

  7. PAT 1001 害死人不偿命的(3n+1)猜想

    1001 害死人不偿命的(3n+1)猜想 (15 分) 卡拉兹(Callatz)猜想: 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把 (3n+1) 砍掉一半.这样一直反复 ...

  8. PAT 1001. 害死人不偿命的(3n+1)猜想 (15)

    卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去,最后一定在某一步得到 n=1.卡拉兹在1950年的世界 ...

  9. pat 1001 A+B Format

    题目链接:传送门 题目简述: 1. 给定两个整数值a,b: 2.范围-1000000 <= a, b <= 1000000: 3.按指定格式输出结果 例:-100000 9 输出: -99 ...

随机推荐

  1. web安全测试&渗透测试之sql注入~~

    渗透测试概念: 详见百度百科 http://baike.baidu.com/link?url=T3avJhH3_MunEIk9fPzEX5hcSv2IqQlhAfokBzAG4M1CztQrSbwsR ...

  2. 《Python基础教程(第二版)》学习笔记 -> 第十一章 文件和素材

    打开文件 open函数用来打开文件,语句如下: open(name[,mode[,buffering]]) open函数使用一个文件名作为唯一的强制参数,然后后返回一个文件对象.模式(mode)和缓冲 ...

  3. 【转载】【内存对齐(二)】__declspec( align(#) )的用法和大小计算

    转自:http://www.cppblog.com/deercoder/archive/2011/03/13/141747.html 感谢作者! 在上面讲到了关于pack的内存对齐和计算方法,这里继续 ...

  4. 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?

    UVa11991 Easy Problem from Rujia Liu?  思路:  构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...

  5. C语言——递归练习

    1.炮弹一样的球状物体,能够堆积成一个金字塔,在顶端有一个炮弹,它坐落在一个4个炮弹组成的层面上,而这4个炮弹又坐落在一个9个炮弹组成的层面上,以此类推.写一个递归函数CannonBall,这个函数把 ...

  6. java计时代码

    public class Test{ public static void main(String[] args) { long startMili=System.currentTimeMillis( ...

  7. 总结的Ubuntu的若干小知识

    一.默认开机直接进入到Ubuntu命令行界面 安装Ubuntu后,开机会默认进入到图形界面,如果不喜欢图形界面,可以通过修改配置,直接进入命令行界面,还行节省100多兆的内存空间.具体方法如下: 修改 ...

  8. Chapter 1 初探Caffe

    首先下载windows下源码: Microsoft 官方:GitHub - Microsoft/caffe: Caffe on both Linux and Windows 官方源码使用Visual ...

  9. B+树|MYSQL索引使用原则

    MySQL一直了解得都不多,之前写sql准备提交生产环境之前的时候,老员工帮我检查了下sql,让修改了一下存储引擎,当时我使用的是Myisam,后面改成InnoDB了.为什么要改成这样,之前都没有听过 ...

  10. Hadoop概念学习系列之Hadoop HA进一步深入(二十八)

    对于Hadoop里的HA,有hdfs HA和resourcemanger HA之分. 1.hdfs HA 为什么引入federation? 因为,这样能达到允许在一个集群里,有多对namenode.通 ...