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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiang_6/article/details/83721818

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;
}

猜你喜欢

转载自blog.csdn.net/xiang_6/article/details/83721818