【题目链接】

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)的结果,输出格式需要使用逗号把数值分割。

提交代码:

 1 #include <stdio.h>
 2
 3 int main(void)
 4 {
 5     int out[10];
 6     int i, len, tmp;
 7     int a, b, c;
 8
 9     scanf("%d %d", &a, &b);
10
11     c = a + b;
12     if(c < 0)
13     {
14         printf("-");
15         c = -c;
16     }
17
18     len = 0;
19     do {
20         out[len] = c % 10;
21         c /= 10;
22         len++;
23     } while(c != 0);
24
25     for(i = 0; i < len; i++)
26     {
27         printf("%d", out[len-1-i]);
28         tmp = len - i - 1;
29         //if((len-i-1)%3 == 0 && (len-i) > 1)
30         if(tmp != 0 && tmp % 3 == 0)
31             printf(",");
32     }
33
34     return 0;
35 }

转载于:https://www.cnblogs.com/utank/p/4775653.html

PAT (Advanced Level) Practise:1001. A+B Format相关推荐

  1. 【PAT (Advanced Level) Practice】1001 A+B Format (20 分)

    #include<iostream> #include<string> #include<cstring> #include<cstdio> #incl ...

  2. 卡拉兹(Callatz)猜想,PAT(Basic Level) Practise NO.1001

    PAT(Basic Level) Practise NO.1001 卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半. 这样 ...

  3. PAT (Advanced Level) Practise 1004 解题报告

    GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 Counting Leaves (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 1600 ...

  4. PAT (Basic Level) Practise:1012. 数字分类

    [题目链接] 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算n1-n2+n3- ...

  5. PAT (Basic Level) Practise:1017. A除以B

    [题目链接] 本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数.你需要输出商数Q和余数R,使得A = B * Q + R成立. 输入格式: 输入在1行中依次给出A和B,中间以1空格 ...

  6. PAT (Basic Level) Practise:1037. 在霍格沃茨找零钱

    [题目链接] 如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 -- 就如海格告诉哈利的:"十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西 ...

  7. PAT (Basic Level) Practise:1013. 数素数

    [题目连接] 令Pi表示第i个素数.现任给两个正整数M <= N <= 104,请输出PM到PN的所有素数. 输入格式: 输入在一行中给出M和N,其间以空格分隔. 输出格式: 输出从PM到 ...

  8. PAT (Advanced Level) Practise 1013. Battle Over Cities (25)

    1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...

  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. 给初恋女孩的信....
  2. 携程是如何把大数据用于实时风控的
  3. OpenCV 入门级一
  4. 2019年以后ArcGIS 调用天地图的资源URL
  5. C语言每日一题之No.12
  6. 通过shell脚本检测MySQL服务信息
  7. 转: DH密钥交换和ECDH原理
  8. 【LaTex使用总结】LaTex,pdflatex,xelatex,xetex等的区别和关系
  9. 2串口两串口三串口多串口3串口转WiFi透传模块实现多通道与服务器透传
  10. 《分布式微服务电商源码》-项目简介
  11. java代码复数包括虚部和实部,C++ complex复数类用法详解
  12. js日期加横杆_JS 替换日期的横杠为斜杠
  13. 关于十六进制发送和显示(VS上位机和下位机)
  14. mysql和ocrcle_oracle 12.1 RAC的ocr磁盘组异常恢复
  15. Android:Handler中的Idle Handler
  16. 什么软件可以将win窗口进行置顶_电脑极简指南,这5个方法可以帮你节约生命...
  17. 一文彻底了解Hive
  18. 周志华西瓜南瓜书学习(一)
  19. 嵌入式课程设计总结(三)
  20. 爆料称华为鸿蒙HarmonyOS 2.0陆续开源,是否为安卓“代码里见”

热门文章

  1. 使用PPMI改进共现矩阵
  2. 计算机语言中tc是什么,新人必须了解的几个TC常用语和脚本基础知识!
  3. android悬浮动态权限,Android 获取判断是否有悬浮窗权限的方法
  4. 提示tun虚拟网卡没有安装_Win10家庭版通过Hyper-V安装Centos7+Python3.7过程总结
  5. 电脑表格制作教程入门_第三节 CorelDRAW制作作品的流程 - CorelDRAW基础入门教程 - 平面设计学院...
  6. Mysql 零距离-入门(六)数据唯一约束性
  7. Connection to @localhost failed. [08001] Could not create connection to database server. Attempt
  8. Java 画精美图形
  9. 获取选中_【字节】如何实现选中复制的功能
  10. 山东大学 2020级数据库系统 实验五