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. PowerDesigner15 增加Domain域

    第一步: 第二步: 点击此按钮,在弹出框中对Domain域打钩即可

  2. python------模块定义、导入、优化 ------time模块

    1.模块介绍 2.time & datetime 3.random 4.os 5.sys 6.shutil 7.json & pickle 8.shelve 9.xml处理 10.ya ...

  3. LeetCode - Number of Recent Calls

    Write a class RecentCounter to count recent requests. It has only one method: ping(int t), where t r ...

  4. 生产环境部署MongoDB副本集(带keyfile安全认证以及用户权限)

    本文同步于个人Github博客:https://github.com/johnnian/Blog/issues/8,欢迎留言. 安装软件包:mongodb-linux-x86_64-3.4.1.tgz ...

  5. CSVN(SVN)命令入门及使用过程中遇到的错误问题汇总

    首先进入web管理界面新建一个版本库 新建一个文件text svn add text #如果提示错误,在后面增加–force svn ci -m 'add text' #如果提示错误,将csvn下的目 ...

  6. Load Balancing OpenSSH SFTP with HAProxy

    In my previous post I described how we setup a Ubuntu Server (12.0.4) as an OpenSSH SFTP server. In ...

  7. NPOI之Excel——设置单元格背景色

    NPOI Excel 单元格颜色对照表,在引用了 NPOI.dll 后可通过 ICellStyle 接口的 FillForegroundColor 属性实现 Excel 单元格的背景色设置,FillP ...

  8. MySQL管理实务处理

    事物处理可以用来维护数据库的完整性,它保证成批的MySQL操作要么完全执行,要么全不执行. 事务:指一组sql语句 回退:指撤销指定的sql语句过程 提交:将未存储的sql语句结果写入数据库表 保留点 ...

  9. Quartz.NET-2.3.3 各种 数据库配置 类别大全

    <!--SqlServer <add key="quartz.dataSource.myDS.connectionString" value="Data So ...

  10. [转] VS2017 打包安装程序

    前言 C#写好一个应用程序,总想分享给自己的朋友或者上架,然而被困在打包之外,这次为大家带来近期我的经验,经过几天的摸索,发现网上的教程并不全面,会给初学者带来很多疑问,这里将做些问题描述与解答. / ...