PAT甲级备考

A+B Format

代码:

#include <iostream>
#include <stack>
using namespace std;
int main() {
    int a, b; cin >> a >> b;
    int c = a + b;
    if(c < 0) cout << "-";
    c = abs(c);
    stack<int> st;
    if(c == 0) {
        cout << 0 << endl;
        return 0;
    }
    int len = 0;
    while(c) {
        st.push(c % 10);
        c /= 10;
        len++;
    }
    while(st.size()) {
        cout << st.top();
        st.pop();
        len--;
        if(len % 3 == 0 && len != 0) cout << ",";
    }
    return 0;
}
posted @ 2022-07-11 09:07  飘向远方丶  阅读(23)  评论(0编辑  收藏  举报