C++

表示数字

http://www.nowcoder.com/questionTerminal/637062df51674de8ba464e792d1a0ac6

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

int main(){
    string str;
    while(cin >> str){
        string res;
        bool begin=false;
        for(auto c: str){
            if(isdigit(c)){
                if(begin==false){
                    begin = true;
                    res+='*';
                }
            }else{
                if(begin){
                    res+='*';
                    begin = false;
                }
            }
            res+=c;
        }
        if(begin) res+='*';
        cout << res << endl;
    }
    return 0;
}
全部评论

相关推荐

2025-12-27 22:36
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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