1001 A+B Format (20 分)

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 Specification:

Each input file contains one test case. Each case contains a pair of integers a and b where −10​^6​​≤a,b≤10^​6​​. The numbers are separated by a space.

Output Specification:

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的范围可以用int型表示,int可以表示10^9的范围,一开始想复杂了,其实直接把字符串逆置后,从高位输出,每输出3个数字输出一个逗号就行了。
 /**
 * Copyright(c)
 * All rights reserved.
 * Author : Mered1th
 * Date : 2019-02-24-19.21.16
 * Description : A1001
 */
 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<unordered_set>
 #include<map>
 #include<vector>
 #include<set>
 using namespace std;

 int main(){
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     int a,b,c;
     scanf("%d%d",&a,&b);
     c=a+b;
     ){
         printf("-");
         c=-c;
     }
     string s=to_string(c);
     reverse(s.begin(),s.end());
     int len=s.length();
     ;i>=;i--){
         )%==&&i!=len-&&i>){
             printf(",");
         }
         printf("%c",s[i]);
     }
     ;
 }
 

1001 A+B Format (20 分)的更多相关文章

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

  2. PAT Advanced 1001 A+B Format (20 分)

    Calculate a+b and output the sum in standard format -- that is, the digits must be separated into gr ...

  3. PAT甲级——1001 A+B Format (20分)

    Calculate a+b and output the sum in standard format – that is, the digits must be separated into gro ...

  4. PAT 1001 A+B Format (20分) to_string()

    题目 Calculate a+b and output the sum in standard format -- that is, the digits must be separated into ...

  5. 【PAT甲级】1001 A+B Format (20 分)

    题意:给两个整数a,b,计算a+b的值并每三位用逗号隔开输出(−1e6​​≤a,b≤1e6​​) AAAAAccepted code: #include<bits/stdc++.h> us ...

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

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

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

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

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

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

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

随机推荐

  1. Bitdefender Internet Security 2013 – 免费3个月

    Bitdefender Internet Security 2013 – 免费3个月大约1分钟参加调查,申请3个月免费,缺陷是…要经过人工审核活动地址: 点此进入申请方法,最好用谷歌翻译(俄文)

  2. 隔行扫瞄/逐行扫瞄的介绍(Interlaced / Progressive)

    隔行扫瞄/逐行扫瞄的介绍(Interlaced / Progressive)   本篇不是着重在理论说明, 而是实际验証结果的分享, 所以只简略解释何谓交错与非交错, 请参考如后. 交错扫瞄(隔行扫瞄 ...

  3. 图片和span水平垂直居中

    <style type="text/css"> .content{ width:20%; height:60px; border:1px solid red; text ...

  4. Java快速排序和归并排序详解

    快速排序 概述 快速排序算法借鉴的是二叉树前序遍历的思想,最终对数组进行排序. 优点: 对于数据量比较大的数组排序,由于采用的具有二叉树二分的思想,故排序速度比较快 局限 只适用于顺序存储结构的数据排 ...

  5. TF-IDF算法(1)—算法概述

    假设现在有一篇很长的文章,要从中提取出它的关键字,完全不人工干预,那么怎么做到呢?又有如如何判断两篇文章的相似性的这类问题,这是在数据挖掘,信息检索中经常遇到的问题,然而TF-IDF算法就可以解决.这 ...

  6. AOP jdk动态代理

    一: jdk动态代理是Spring AOP默认的代理方法.要求 被代理类要实现接口,只有接口里的方法才能被代理,主要步骤是先创建接口,接口里创建要被代理的方法,然后定义一个实现类实现该接口,接着将被代 ...

  7. 51Nod 1066:Bash游戏 (巴什博弈)

    1066 Bash游戏  基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 有一堆石子共有N个.A B两个人轮流拿,A先拿.每次最少拿1颗,最多拿K颗,拿到 ...

  8. C#浮点数保留位数

    C#浮点数保留位数 这里用String.Forma("{0:F}",x);来解决. 下面是试验和截图 using System; using System.Collections. ...

  9. Spring4.3整合Hibernate4.3搭建Spring MVC

    1,web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&qu ...

  10. VLOOKUP函数的使用方法

    VLOOKUP(lookup_value,table_array,col_index_num,range_lookup) lookup_value:为在查找范围的第一列中要查找的值.比如下图的 C2 ...