题解 | 游游的数字圈

游游的数字圈

https://www.nowcoder.com/practice/16eafa41a4a242b8870cb2c5420ae089

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

int main(){
    string str;
    cin>>str;
    int ans = 0;
    for(auto x : str){
        if(x=='0'||x=='6'||x=='9')ans++;
        else if(x=='8') ans += 2;
    }
    cout<<ans;

    return 0;
}

for循环判断,如果当前的字符为'0'or'6'or'9',ans += 1,如果当前字符为'8',ans+=2

#牛客春招刷题训练营#https://www.nowcoder.com/discuss/727521113110073344

全部评论

相关推荐

Clavoss:一眼AI,死亏
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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