Codeforces 1070H - BerOS File Suggestion 暴力 (2018-2019 ICPC, NEERC)

ACVoyager發表於2018-11-04

CF: *1600

 

題意:給定n個字串(長度最大8),q個查詢,問上述n個串中有多少個串的子串是這個查詢的串,任意輸出一個原串

思路:直接暴力

 

#include<bits/stdc++.h>

using namespace std;

#define out fflush(stdout);
#define fast ios::sync_with_stdio(0),cin.tie(0);

#define FI first
#define SE second

typedef long long ll;
typedef pair<int,int> P;

const int maxn = 2e5 + 7;
const int INF = 0x3f3f3f3f;
const ll mod = 998244353;





int n, q;
map<string, int> mp;
map<string, bool> vis;
map<string, string> ans;

int main() {fast;

    cin >> n;
    string s;
    for(int i = 1; i <= n; ++i) {
        cin >> s;
        vis.clear();
        for(int l = 0; l < s.size(); ++l) {
            string t;
            for(int r = l; r < s.size(); ++r) {
                t.push_back(s[r]);
                if(!vis[t]) {
                    mp[t]++;
                    ans[t] = s;
                    vis[t] = true;
                }
            }
        }
    }
    cin >> q;
    for(int i = 1; i <= q; ++i) {
        cin >> s;
        int cnt = mp[s];
        if(cnt) {
            cout << cnt << " " << ans[s] << endl;
        }
        else {
            cout << "0 -" << endl;
        }
    }


    return 0;
}

 

相關文章