pat 1001. A+B Format (20)

来源:互联网 发布:淘宝退款流程手机 编辑:程序博客网 时间:2024/06/06 13:14

简单题

#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的情况忘记了

原创粉丝点击