This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
int n, m;
vector<string> S;
int solve(string pref, string suf) {
int ans = 0;
for (int i = 0; i < n; i++) {
string cur = S[i];
if (cur.size() < pref.size() or cur.size() < suf.size()) continue;
if (cur.substr(0, pref.size()) == pref and cur.substr(cur.size() - suf.size(), suf.size()) == suf) ans++;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
S.resize(n);
for (int i = 0; i < n; i++) {
cin >> S[i];
}
while (m--) {
string pref, suf;
cin >> pref >> suf;
cout << solve(pref, suf) << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |