这道题是道纯模拟的题目,暴力模拟就可以了。
思路
当把小 K 的文章和所有文章输入完成后就用双重循环。如果有相同的字母,就把计数器加一。最后输出计数器,如果计数器为零再输出 Good job!
,否则输出 Make persistent efforts.
。
不用担心超时,因为 1 ≤ n ≤ 1 0 4 1\le n\le10^4 1≤n≤104,字符串长度不超过 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;
}