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<stack>
using namespace std;
int main() {
long a,b;
cin>>a>>b;
long res=a+b;
if(res==){
cout<<;
system("pause");
return ;
}
bool sign;
int m=;
if(res<) {
sign=false;
res=-res;
}
else sign=true;
stack<char> sta;
while(res!=){
m++;
sta.push(res%+'');
res/=;
if(m%==) sta.push(',');
}
if(sta.top()==',') sta.pop();
if(!sign) cout<<"-";
while(!sta.empty()){
cout<<sta.top();
sta.pop();
}
system("pause");
return ;
}

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

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

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

  3. PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1035 Password (20 分) 凌宸1642 题目描述: To prepare for PAT, the judge someti ...

  4. PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...

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

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

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

  7. PAT甲 1001. A+B Format (20) 2016-09-09 22:47 25人阅读 评论(0) 收藏

    1001. A+B Format (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Calculate ...

  8. 【PAT】1001. A+B Format (20)

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

  9. PAT 1001 A+B Format (20分) to_string()

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

随机推荐

  1. mysql中查看ef或efcore生成的sql语句

    http://www.solves.com.cn/it/sjk/MYSQL/2019-07-01/1336.html 涉及命令 1.开启general log模式 MySQL>set globa ...

  2. leetcode-mid-sorting and searching - 240. Search a 2D Matrix II -NO

    mycode   time limited def searchMatrix(matrix, target): def deal(data): if not data: return False ro ...

  3. 浏览器默认样式及reset

    写在前面 首先纠正一个易错概念.div并非生来就是块元素,而是每个浏览器都有一套默认的css样式(优先级最低),默认样式里会把div设置成display: block;还有margin,padding ...

  4. yum基本使用方法

    yum 是 Fedora RHEL Centos SUSE等linux 发行版的 软件包管理工具 通过 执行 man yum 查看yum的帮助信息 可以知道 yum makecache 是将服务器上的 ...

  5. vue-router实现组件间的跳转---参数传递

    四.通过VueRouter来实现组件之间的跳转:参数的传递 login ---用户名--->main ①明确发送方和接收方②配置接收方的路由地址 {path:'/myTest',componen ...

  6. python接口自动化:绕过验证码登录

    上线产品的登录接口会有验证码,一般可以通过添加cookie的方式绕过验证码. 一.抓登录的cookie 1. 先手动登录一次,然后用fiddler抓取这个cookie,再直接把这个值添加到cookie ...

  7. python gevent(协程模块)

    Python通过yield提供了对协程的基本支持,但是不完全.而第三方的gevent为Python提供了比较完善的协程支持. gevent是第三方库,通过greenlet实现协程,其基本思想是: 当一 ...

  8. 【Qt开发】事件循环与线程 二

    事件循环与线程 二 Qt 线程类 Qt对线程的支持已经有很多年了(发布于2000年九月22日的Qt2.2引入了QThread类),Qt 4.0版本的release则对其所有所支持平台默认地是对多线程支 ...

  9. centos 7 里如何判断IP是否合法

    ip=123.23.2.32; [[ $ip =~ ^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9 ...

  10. java8 stream取出 最大值/最小值

    注:转载请注明出处!!! 这里直接用取出多个对象中某个值 最大/最小 来进行举例 直接看代码 /** * 时间测试类 */ class TimeTest { private Date time; pu ...