这题样例对?0分!我想知道原因

B2078 含 k 个 3 的数

Better_Tomorrow @ 2024-05-19 19:31:22

#include<bits/stdc++.h>

using namespace std;

int main() {
    long long k;
    int sum = 0;
    string a;
    cin >> a >> k;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] - '0' == 3) {
            sum++;
        }
    }
    if (sum == k) {
        cout << "yes";
    } else {
        cout << "no";
    }
    return 0;
}

by Better_Tomorrow @ 2024-05-19 19:33:06

我看题解全用的是while,可我跟题解的思路应该没错吧?


by QBW1117 @ 2024-05-19 19:33:23

输出 YES,否则,输出 NO。


by QBW1117 @ 2024-05-19 19:33:32

大写


by ZhangXuKun @ 2024-05-19 19:45:40

如果输入的k大于字符串a的长度,那么即使字符串a中包含3的数量等于k,程序也会输出"no"


by Lizichen_licis @ 2024-05-19 19:47:17

@QBW1117


|