70分求调(玄关)

B2078 含 k 个 3 的数

ABCD124 @ 2024-08-24 14:35:10

#include <bits/stdc++.h>
using namespace std;
string a;
int k, s;

int main() {
    cin >> a >> k;
    for (int i = 1; i <= a.size(); i++) {
        if (a[i] == '3') {
            s++;
        }
    }
    if (s == k) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}

by szrgjxms @ 2024-08-24 14:36:04

字符串的下标是从 0 开始的


by szrgjxms @ 2024-08-24 14:36:39

for (int i = 0; i < a.size(); i++) {
    if (a[i] == '3') {
        s++;
    }
}

应该要这样改


by Qinglan2011 @ 2024-08-24 14:39:27

下标从零开始


by szrgjxms @ 2024-08-24 14:43:47

@ABCD124


by dyh_120 @ 2024-08-24 14:57:04

@ABCD124 下标从零开始


|