PAT Advanced 1001 A+B Format (20 分)
2024-10-07 08:19:03
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 ;
}
最新文章
- 面向对象Part4
- C/C++学习链接
- Ext3文件系统mount选项和文件属性介绍
- 《Storm入门》中文版
- Jquery,ajax返回json数据后呈现到html页面的$.post方式。
- selenium项目总结(UI自动化测试平台搭建、测试报告生成、邮件转发)
- poj 1180 斜率优化dp
- 【AngularJs】---表单验证
- ANT的下载和安装
- Usage、Usage Minimum和Usage Maximum项目详解
- 警告:‘xxxx’ 将随后被初始化
- 教程:查找内存泄漏 (JavaScript)
- CSharp设计模式读书笔记(17):迭代器模式(学习难度:★★★☆☆,使用频率:★★★★★)
- mysql 触发器(trigger)
- Java | 原来 try 还可以这样用啊?!
- python笔记三(list、tuple)
- 对C#热更新方案ILRuntime的探究
- 自己动手写Redis客户端- Redis协议(1)
- app开发中,前后端使用AES进行数据加密传输
- Nmap扫描命令使用详解