题解:P11137 [APC001] B - Checker

这道题是道纯模拟的题目,暴力模拟就可以了。

思路

当把小 K 的文章和所有文章输入完成后就用双重循环。如果有相同的字母,就把计数器加一。最后输出计数器,如果计数器为零再输出 Good job!,否则输出 Make persistent efforts.

不用担心超时,因为 1 ≤ n ≤ 1 0 4 1\le n\le10^4 1n104,字符串长度不超过 10 10 10,最坏复杂度不会超时。

AC code

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int len = s.length();
    int h = (len + 1) / 2;
    string target;
    vector<string> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int cnt = 0;
    for (const string& p : a) {
        int tmp = 0;
        for (int i = 0; i < len; ++i) {
            if (s[i] == p[i]) {
                ++tmp;
            }
        }
        if (tmp >= h) {
            ++cnt;
        }
    }
    cout << cnt << endl;
    if (cnt == 0) {
        cout << "Good job!" << endl;
    } else {
        cout << "Make persistent efforts." << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值