1001 A+B Format (20 分)

题意:给出俩个整数a,b(不超过10^9) ,求a+b的值 ,并按照xxx,xxx,xxx的格式输出

#include <iostream>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    string s = to_string(a + b);
    int len = s.length();
    for (int i = 0; i < len; i++) {
        cout << s[i];
        if (s[i] == '-') continue;
        if ((i + 1) % 3 == len % 3 && i != len - 1) cout << ",";
    }
    return 0;
}

 

posted @ 2018-12-07 19:13  12-num  阅读(1062)  评论(0编辑  收藏  举报