题解 | #表示数字#

表示数字

https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6

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

int main() {
    string s;
    getline(cin, s);

    string ans;
    bool isnum = false;
    for (auto c : s) {
        if (isnum) {
            if (c >= '0' && c <= '9') {
                ans += c;
            } else {
                isnum = false;
                ans = ans + '*' + c;
            }
        } else {
            if (c >= '0' && c <= '9') {
                isnum = true;
                ans = ans + '*' + c;
            } else {
                ans = ans + c;
            }
        }
    }
    if (isnum) {
        ans += '*';
    }

    cout << ans;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

小鹏、大疆、米哈游、MinMax小鹏上午投的下午就约面,进度未免也太快了
蛇年行大运fff:哥们 盗贴有意思吗,我发xhs上的给你搬过来了😅😅😅
点赞 评论 收藏
分享
06-23 11:43
门头沟学院 Java
allin校招的烤冷...:我靠,今天中午我也是这个hr隔一个星期发消息给我。问的问题还是一模一样的😅
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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