-
Notifications
You must be signed in to change notification settings - Fork 0
/
POJ1628
65 lines (55 loc) · 1.17 KB
/
POJ1628
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// main.cpp
// POJ1628
//
// Created by B-YMac on 14-9-17.
// Copyright (c) 2014年 B-YMac. All rights reserved.
//
#include <iostream>
#include<string>
using namespace std;
long long code(string &s){
long long res = 0, base = 1;
for(int i = 0; i < s.size(); i++){
if(s[i]>='a')
res |= (base<<(s[i]-'a'));
else
res |= (base<<(s[i]-'A'+26));
}
return res;
}
string decode(long long t){
string res;
int i = 0;
while(t){
if(t&1)
res.push_back(i<26?'a'+i:'A'+i-26);
t>>=1;
i++;
}
return res;
}
long long map[201][2];
int n,m;
int main(int argc, const char * argv[])
{
cin >> m >> n;
string a,b,c;
for(int i = 0; i < m; i++){
cin >> a >> c >> b;
map[i][0] = code(a), map[i][1] = code(b);
}
for(int i = 0; i < n; i++){
string t;
cin >> t;
long long p = code(t),st;
do{
st = p;
for(int j = 0; j < m; j++)
if((p&map[j][0])==map[j][0])
p |= map[j][1];
}while(p!=st);
cout << decode(p) << endl;
}
return 0;
}