题解 | 添加逗号

添加逗号

https://www.nowcoder.com/practice/f51c317e745649c0900996fd3f683aed

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

int main() {
    string n;
    cin>>n;
    string a,b,c ;
    string N;
    if (n.size()<=3) {
    a=n.substr(0,3);
    N=a;
    }
    if (n.size()>3 && n.size()<=6) {
    a=n.substr(0,n.size()-3);
    b=n.substr(n.size()-3,3);
    N=a+','+b;
    }
    if (n.size()>6) {
    a=n.substr(0,n.size()-6);
    b=n.substr(n.size()-6,3);
    c=n.substr(n.size()-3,3);
    N=a+','+b+','+c;
    }
    cout<<N;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务