我的代码:

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

主要考察对下标的观察。


浮生若梦
1 声望0 粉丝

夫天地者万物之逆旅也,光阴者百代之过客也。


引用和评论

0 条评论