题解 | #表示数字#

表示数字

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

#include <bits/stdc++.h>
using namespace std;

int main() {
    string str;
    getline(cin, str);
    for(int i=0; i<str.size(); i++){
        if(i == 0 && (str[i]>='0' && str[i]<='9') &&  (str[i+1]<'0' || str[i+1]>'9')) cout << "*" << str[i] << "*";
        else if(i == 0 && (str[i]>='0' && str[i]<='9') &&  (str[i+1]>='0' || str[i+1]<='9')) cout << "*" << str[i];
        else if(i == str.size()-1 && (str[i]>='0' && str[i]<='9') &&  (str[i-1]<'0' || str[i-1]>'9')) cout << "*" << str[i] << "*";
        else if(i == str.size()-1 && (str[i]>='0' && str[i]<='9') &&  (str[i-1]>='0' || str[i-1]<='9')) cout << str[i] << "*";
        else if( (str[i]>='0' && str[i]<='9') &&  (str[i-1]<'0' || str[i-1]>'9') &&  (str[i+1]<'0' || str[i+1]>'9')) cout << "*" << str[i] << "*";
        else if( (str[i]>='0' && str[i]<='9') &&  (str[i-1]<'0' || str[i-1]>'9') &&  (str[i+1]>='0' && str[i+1]<='9')) cout << "*" << str[i];
        else if( (str[i]>='0' && str[i]<='9') &&  (str[i-1]>='0' || str[i-1]<='9') &&  (str[i+1]<'0' || str[i+1]>'9')) cout << str[i] << "*";
        else cout << str[i];
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

吃不饱的肱二头肌很想退休:tnnd 我以为选妹子呢,亏我兴高采烈的冲进来😠
投递快手等公司10个岗位
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务