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. vim 的编辑模式 命令模式

    1.vim的编辑模式    进入编辑模式 按键: a  i  o a: 表示在光标当前的,后面开始插入,写数据 i : 则表示 前面 . o : 表面在光标当前的,下一行开始写入数据. O : 大写的 ...

  3. C# NPOI使用

    HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = workbook.CreateSheet( "Sheet1&quo ...

  4. hdu4553 约会安排 线段树

    寒假来了,又到了小明和女神们约会的季节. 小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的大段发言后热情回复“呵呵”,所以,小明的最爱就是和女神们约会.与此同时,也有很多基友找他开黑,由于数量实 ...

  5. 针对IE浏览器的CSS样式(兼容性)

    1. IE hacks: "_"  是IE6 专有的hack; "\9" 对IE6-IE10都有效: "\0"对IE8-IE10都有效: & ...

  6. LeetCode - Convert BST to Greater Tree

    Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original B ...

  7. 直面Java 第004期。

    什么是值传递,什么是引用传递.为什么说Java中只有值传递 对于初学者来说,要想把这个问题回答正确,是比较难的.在第二天整理答案的时候,我发现我竟然无法通过简单的语言把这个事情描述的很容易理解,遗憾的 ...

  8. gorm-Duplicate-entry

    gorm  insert  data to mysql tips: (Error 1062: Duplicate entry '267857' for key 'PRIMARY') reason: u ...

  9. python从文本中提取某酒店机顶盒号和智能卡号

    1.某项目中经常遇到需要关闭一些机顶盒消费权限.但是给过来的不是纯字符串,需要自己提取. 有400多个机顶盒和智能卡.nodepad++的列块模式也可以提取,但是还是稍微麻烦,因为列不对等 先复制到文 ...

  10. 轻量级web框架cicada----(转)

    源码地址: https://github.com/TogetherOS/cicada 快速启动 下面来看看如何快速启动一个 HTTP 服务. 只需要创建一个 Maven 项目,并引入核心包. < ...