题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400

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 −. 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
 #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
using namespace std;
int main()
{
int n,m,sum;
while(cin>>n>>m){
sum=n+m;
if(sum==){
cout<<<<endl;
continue;
}
int flag=;
if(sum<){
flag=;
sum=-sum;
}
char c='-';
stack<char> s;
int t=;
while(sum){
c=sum%+'';
s.push(c);
t++;
if(t%==&&sum/) s.push(',');
sum/=;
}
if(flag) s.push('-');
while(!s.empty()){
cout<<s.top();
s.pop();
}
cout<<endl;
}
return ;
}
 

PAT (Advanced Level) Practice 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 Level) Practice 1027 Colors in Mars (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...

  3. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  4. PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642 题目描述: With the 2010 FIFA World Cu ...

  5. PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...

  6. PAT (Advanced Level) Practice 1001 A+B Format 分数 20

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

  7. PAT (Advanced Level) Practice 1027 Colors in Mars (20 分)

    People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...

  8. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) (进制转换,回文数)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  9. PAT (Advanced Level) Practice 1054 The Dominant Color (20 分)

    Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of i ...

随机推荐

  1. vue2 里边使用 swiper2

    找过了很多轮播图插件,我都不会用,还是回到swiper2吧... npm install swiper@2.7.6 --save-dev 封装成一个组件 <template> <di ...

  2. __x__(4)0905第二天__软件架构

    软件架构 C/S 架构,客户端/服务器,用户通过客户端使用软件. 一般的应用软件都是 C/S 架构,如 QQ,360 等等. C 为 Client,用户电脑使用的软件. S 为 Server,服务器, ...

  3. (82)Wangdao.com第十六天_JavaScript 异步操作

    异步操作 单线程模型 指的是,JavaScript 只在一个线程上运行 也就是说,JavaScript 同时只能执行一个任务,其他任务都必须在后面排队等待 注意,JavaScript 只在一个线程上运 ...

  4. Android总结之json解析(FastJson Gson 对比)[申明:来源于网络]

    Android总结之json解析(FastJson Gson 对比)[申明:来源于网络] 地址:http://blog.csdn.net/u014031072/article/details/5392 ...

  5. .net经典书籍

    C#敏捷开发实践 C#从现象到本质 NET开发经典名著:Visual Studio 2017高级编程(第7版) 代码大全(第2版) C#高级编程(第10版 C#6&.NET Core1.0)/ ...

  6. 《SQL Server性能调优实战》知识点汇总

    2.4数据库结构的设计 好的性能出自好的设计 尽可能添加数据完整约束(非空约束.默认值约束.CHECK约束.唯一约束.外键约束)等,这些约束的添加将有助于数据库关系引擎分析执行计划. 尽可能小的字段类 ...

  7. Spring boot 国际化自动加载资源文件问题

    Spring boot 国际化自动加载资源文件问题 最近在做基于Spring boot配置的项目.中间遇到一个国际化资源加载的问题,正常来说只要在application.properties文件中定义 ...

  8. Tkinter 项目-屏保

    参考教程,以及网上资料,针对小白更好理解 关于tkinter的屏保涉及的知识点和思想 项目分析: 屏保启动方式:手动,自动 敲击键盘或者移动鼠标后,或者其他引发事件,则停止 如果屏保是一幅画的话,则没 ...

  9. Java学习-051-Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError

    错误信息:Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting St ...

  10. C语言扫盲及深化学习

    c语言特点: (1)效率高 (2)控制性强 (3)硬件亲和性好 (4)可移植性高 一.关于注释 c语言中注释不能嵌套,因此注释代码时一定要注意源代码中是否已经存在注释.要从逻辑上删除一段代码,利用预编 ...