pat甲级打卡-1001 A+B Format

#include<bits/stdc++.h>
using namespace std;


int main(){
    int a,b;
    cin>>a>>b;
    int res=a+b;
    string s=to_string(res);
    int cnt=1;
    for(int i=s.size()-1;i>=0;i--){
        if(cnt%3==0 && i-1>=0 &&s[i-1]!='-'){
            s=s.substr(0,i)+","+s.substr(i);
           // i--;
        }
        cnt++;
    }
    cout<<s;
    return 0;
   
}
posted @ 2022-04-16 23:17  秋月桐  阅读(13)  评论(0编辑  收藏  举报