PTA 1001 A+B Format

#include <iostream>
#include <string>
using namespace std;

int main(int argc, const char * argv[]) {
    int a,b;
    int sum;
    string str;
    scanf("%d %d",&a,&b);
    sum=a+b;
    str=to_string(sum);
    int count=0;
    unsigned long int temp=str.length();
    unsigned long int num;
    if(sum<0)
        num=(temp-2)/3;
    else
        num=(temp-1)/3;
    while (temp>0) {
        if(temp==num*3){
            printf(",");
            num--;
        }
        printf("%c",str.at(count));
        count++;
        temp--;
    }
    cout<<endl;
        
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40215528/article/details/83051896
今日推荐