Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
859 B
28
Indexable
Never
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const ll INF = 1e18;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    map<string, ll> mp;
    for (ll i = 0; i < n; i++) {
        string t;
        cin >> t;
        string r;
        ll sz = (ll)t.size();
        for (ll j = 0; j < sz; j++) {
            r += t[j];
            ll s = sz - j - 1;
            bool f = true;
            for (ll k = s; k < sz; k++) {
                if (t[k] != r[k - s]) {
                    f = false;
                    break;
                }
            }
            if (f) {
                mp[r]++;
            }
        }
    }
    ll m;
    cin >> m;
    for (ll i = 0; i < m; i++) {
        string s;
        cin >> s;
        cout << mp[s] << '\n';
    }
}