题目链接: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. __x__(42)0910第六天__表格布局 老旧的布局方法

    table 布局 不易于维护,耦合太严重了. 不利于搜索引擎检索. 效果图: html代码: <!doctype html> <html> <head> <m ...

  2. mongodb聚合命令

    聚合aggregate 聚合(aggregate)是基于数据处理的聚合管道,每个文档通过一个由多个阶段(stage)组成管道,可以对每个阶段的管道进行分组.过滤等功能,然后经过一系列的处理,输出相应的 ...

  3. 【搜索2】P1706 全排列问题

    题目描述 输出自然数1到n所有不重复的排列,即n的全排列,要求所产生的任一数字序列中不允许出现重复的数字. 输入输出格式 输入格式: n(1≤n≤9) 输出格式: 由1-n组成的所有不重复的数字序列, ...

  4. 关于redis分布式锁实现原理

    具体详情 http://www.cnblogs.com/SUNSHINEC/p/8302540.html

  5. GParted: GNOME Partition Editor, sharp weapon to modify disk partitions.

    GParted Projects GNOME Partition Editor for creating, reorganizing, and deleting disk partitions. It ...

  6. RobotFramework环境配置:默认以管理员权限运行cmd

    设置cmd以管理员权限运行 目的:创建或删除文件等命令时,需要管理员权限运行cmd(linux以root用户登录).   例如,创建日志目录.   方法一: 1.激活administrator用户 2 ...

  7. init();

    <script language="javascript" type="text/javascript">window.onload = funct ...

  8. AppStore关键词覆盖法则标记

    https://www.jianshu.com/p/6b39b0dc6ba4 多批设置关键字

  9. mysql GROUP_CONCAT 查询某个字段(查询结果默认逗号拼接)

    Mysql 的 GROUP_CONCAT 函数默认将查询的结果用逗号拼接并返回一个字符串,如:李四,long,张三 1. 常用方式 select GROUP_CONCAT(user_name) use ...

  10. VUE-009-页面打开时初始化配置项内容

    网页开发过程中,尤其是在表单开发过程中,不可避免的会有各种各样的基础数据需要展示,供用户使用.例如,大家在办理信用卡时,经常需要填写各种表单数据,其中:性别(男.女).学历(高中及以下.大专.本科.研 ...