题解 | 游游的数字圈

游游的数字圈

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

用string数组来存每一位的数字

遍历数组,如果是数字为[0][6][9],则cnt+=1;

如果是[8]cnt+=2;

最后输出cnt;

#include "bits/stdc++.h"

using namespace std;
#define int long long
#define endl "\n"
#define PII pair<int,int>
#define PIII pair<int,PII>
const int MOD = 1e9 + 7;
const int N = 3e5;

bool cmp(PII p1, PII p2) {
    return p1.first + p1.second < p2.first + p2.second;
}

void slu() {
    string t;
    cin >> t;
    int cnt = 0;
    for (int i = 0; i < t.size(); i++) {
        if (t[i] == '8')cnt += 2;
        else if (t[i] == '0' || t[i] == '6' || t[i] == '9')cnt++;
    }
    cout << cnt;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
//    cin >> T;
    T = 1;
    while (T--)slu();

}

#牛客春招刷题训练营#
全部评论

相关推荐

05-24 14:12
门头沟学院 Java
点赞 评论 收藏
分享
05-23 20:31
已编辑
武汉大学 Java
内向的柠檬精在研究求职打法:注意把武大标粗标大 本地你俩不是乱杀
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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