Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define FOR(i,a,b) for(int i = (a); i < (b); ++i)
- #define RFOR(i,b,a) for(int i = (b)-1; i >= (a); --i)
- #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
- #define FILL(a,value) memset(a, value, sizeof(a))
- #define SZ(a) (LL)a.size()
- #define ALL(a) a.begin(), a.end()
- #define PB push_back
- #define MP make_pair
- typedef long long LL;
- typedef vector<int> VI;
- typedef pair<int, int> PII;
- const double PI = acos(-1.0);
- const int INF = 1000 * 1000 * 1000 + 7;
- const LL LINF = INF * (LL)INF;
- map<string, vector<string> > files;
- map<string, vector<string> > users;
- int count(string& a, string& b)
- {
- int res = 0;
- int ind = 0;
- FOR (i, 0, SZ(b))
- {
- while(ind < SZ(a) && a[ind] != b[i])
- {
- ind++;
- res++;
- }
- if (res > 2) return INF;
- if (ind == SZ(a)) return INF;
- ind++;
- }
- while(ind < SZ(a))
- {
- ind++;
- res++;
- }
- return res;
- }
- int main()
- {
- //freopen("in.txt", "r", stdin);
- //ios::sync_with_stdio(false); cin.tie(0);
- int tt;
- cin>>tt;
- FOR (ttt, 0, tt)
- {
- files.clear();
- users.clear();
- int n;
- cin>>n;
- FOR (i, 0, n)
- {
- string dir, file;
- cin>>dir>>file;
- files[dir].PB(file);
- }
- cin>>n;
- FOR (i, 0, n)
- {
- string name;
- cin>>name;
- int k;
- cin>>k;
- FOR (i, 0, k)
- {
- string dir;
- cin>>dir;
- users[name].PB(dir);
- }
- }
- printf("DATA SET #%d\n", ttt + 1);
- cin >> n;
- FOR (i, 0, n)
- {
- string name, file;
- cin>>name>>file;
- vector<string>& dirs = users[name];
- vector<pair<string, string> > res;
- FOR (it, 0, 3)
- {
- FOR (j, 0, SZ(dirs))
- {
- vector<string>& fs = files[dirs[j]];
- FOR (k, 0, SZ(fs))
- {
- if (count(fs[k], file) == it) res.PB(MP(fs[k], dirs[j]));
- }
- if (SZ(res)) break;
- }
- if (SZ(res)) break;
- }
- sort(ALL(res));
- printf("%s REQUESTED %s\n", name.c_str(), file.c_str());
- FOR (i, 0, SZ(res))
- {
- printf("FOUND %s IN %s\n", res[i].first.c_str(), res[i].second.c_str());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement