您的位置:首页 > 其它

pat 1001. A+B Format (20)

2017-12-10 08:26 405 查看
简单题

#include <iostream>
#include <cstring>
#include <stack>
#include <cmath>
using namespace std;

int main(){
ios::sync_with_stdio(false);
int a,b;
cin>>a>>b;
bool flag = false;
int c = a+b;
if(!c) cout<<c;
stack<char>res;
if(c<0){
flag = true;
}
c = c>0?c:-c;
int tmp;
int count = 0;
while(c){
tmp=c%10;
c /=10;
res.push(tmp+'0');
count++;
if(count==3 && c){
res.push(',');
count =0;
}
}
if(flag) cout<<'-';
while(res.size()){
cout<<res.top();
res.pop();
}
return 0;
}


但是在第一次写完之后有一个测试点没有过

因为a+b=0的情况忘记了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: