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. css命名和书写规范

    前言 在项目开发中对于css名字的命名和书写老是感觉很混乱,这对于代码的可读性以及维护提出了挑战,所以在闲暇之余看了一些这方面的内容,现总结如下... 1.命名规则说明 所有的命名最好都小写 属性的值 ...

  2. 实现Runable接口

    步骤 定义一个实现Runable接口的类,在类中实现run()方法(线程执行事件的方法).创建一个上述类的对象:Thread t=new Thread(new MyThreadt.start());调 ...

  3. javadoc生成文档

    标签(空格分隔): javadoc java生成html的文档: 要生成注释文档html格式,java里面提供一个工具:javadoc 例如: javadoc -d myhelp -author -v ...

  4. AI-人工智能/机器学习 seetafaceJNI

    基于中科院seetaface2进行封装的JAVA人脸识别库,支持人脸识别.1:1比对.1:N比对. 项目介绍 基于中科院seetaface2进行封装的JAVA人脸识别算法库,支持人脸识别.1:1比对. ...

  5. What is 'typeof define === 'function' && define['amd']' used for?

    What is 'typeof define === 'function' && define['amd']' used for? This code checks for the p ...

  6. Elasticsearch Java Rest Client API 整理总结 (一)

    http://www.likecs.com/default/index/show?id=39549

  7. IO负载高来源定位pt-ioprofile

    1.使用top -d 1 查看%wa是否有等待IO完成的cpu时间,简单理解就是指cpu等待磁盘写入完成的时间:IO等待所占用的cpu时间的百分比,高过30%时IO压力高: 2.使用iostat -d ...

  8. Android传感器【转】

    本文转载自:http://blog.csdn.net/ffmxnjm/article/details/52101592?locationNum=3&fps=1 传感器的意义 事实上,目前智能手 ...

  9. RAC_单实例_DG 关于两端创建表空间数据文件路径不一致的问题注意点

    RAC_单实例_DG 关于两端创建表空间数据文件路径不一致的问题注意点 主库SYS@orcl1>show parameter db_file_name_convert NAME TYPE VAL ...

  10. windows下eclipse打不开

    报错找不到jre等东西 因为eclipse到不到javaw.exe 将其写入eclipse.ini即可 在eclipse.ini的前面加上 -vm D:\dev_tool\java\jdk1.7.0_ ...