1001 A+B Format (20)(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

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

注意几个输出点:-991  991 1001 -1001
 #include<iostream>
#include <sstream>
#include<string>
#include<stack>
#include<typeinfo> using namespace std; int main()
{
int a,b,flag=,temp=; cin>>a>>b; a+=b; if(a<)
{
flag=;
cout<<"-";
} stringstream ss;
ss<<a; string str=ss.str(); stack<char> s; for(int i=str.length()-;i>=flag;--i)
{
s.push(str[i]);
++temp; if(temp%== && i->=flag)
s.push(',');
} while(!s.empty())
{
cout<<s.top();
s.pop();
} cout<<endl; return ;
}

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

  1. PAT甲级 1001 A+B Format

    题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 1001 A+B Format ( ...

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

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

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

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

  5. PAT 甲级 1001 A+B Format

    https://pintia.cn/problem-sets/994805342720868352/problems/994805528788582400 Calculate a + b and ou ...

  6. 1001 A+B Format (20 分)

    1001 A+B Format (20 分) Calculate a+b and output the sum in standard format -- that is, the digits mu ...

  7. PAT甲级:1136 A Delayed Palindrome (20分)

    PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...

  8. PAT甲级:1036 Boys vs Girls (25分)

    PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...

  9. PAT甲级:1089 Insert or Merge (25分)

    PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one i ...

随机推荐

  1. lesson3-神经序列模型I-小象

    优化目标函数: batch gradient descent:必须便利all训练数据 -->随机梯度下降,但不稳定~一个数据点就更新,快但不稳定-->minibatch,取m个随机数据点, ...

  2. java-多态中成员访问特点-父类引用指向子类对象

    多态前提: - 要有继承关系. - 要有方法重写. - 要有父类引用指向子类对象. 1.成员变量:编译看左边(父类),运行看左边(父类) 2.成员方法:编译看左边(父类),运行看右边(子类),动态绑定 ...

  3. C++学习(四)(C语言部分)之 二进制

    二进制学习时的笔记(其实也没什么用,留着给自己看的) 二进制简介只有 0 1 优点:1.二进制状态简单2.可靠性.稳定性高3.运算规则简单,简化设计4.通用性强 二进制计算正数二进制十进制转二进制(除 ...

  4. 【EOJ Monthly 2018.7】【D数蝌蚪】

    https://acm.ecnu.edu.cn/contest/92/problem/D/ D. 数蝌蚪 Time limit per test: 2.0 seconds Memory limit:  ...

  5. day43 数据库学习egon的博客 视图、触发器、事务、存储过程、函数

    一 视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,可以将该结果集当做表来使用. 使用视图我们可以把查询过程中的 ...

  6. 使用netstat、lsof查看端口占用情况

    netstat netstat用来查看系统当前系统网络状态信息,包括端口,连接情况等,常用方式如下:   netstat -atunlp,各参数含义如下:   -t : 指明显示TCP端口 -u : ...

  7. vmware中扩充磁盘

    刚开始装虚拟机中的系统时,只分了20G的空间大小,随着不断的使用,结果在安装一个软件的时候提示我磁盘空间不足 用"df -h "查看"/"目录使用率已达到90% ...

  8. c++简单的ATL COM开发和调用实例

    1.打开VS2010.新建ATL COM 项目.步骤:"文件" -->"新建" -->"项目",选择"Visual C ...

  9. php 数组排序 按照某字段

    $arr=[     array(         'name'=>'小坏龙',         'age'=>28     ),     array(         'name'=&g ...

  10. 收集到的关于 freeCodeCamp 中文社区

    收集到的关于 freeCodeCamp 中文社区 freeCodeCamp 是一个免费学习编程的开源项目. 中文有两个,一个是 cn 一个是 one. one 是新版的,相关于硬分支.(具体什么原因, ...