Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define N 1000005
- using namespace std;
- char s[N], s1[2], s2[N];
- int C[N];
- int main(){
- int tc = 0;
- scanf("%d", &tc);
- while(tc--){
- scanf("%s", s);
- int m;
- scanf("%d", &m);
- for(int i = 0; i < 26; i++)C[i] = i;
- for(int i = 0; i < m; i++){
- scanf("%s%s", s1, s2);
- C[s2[0] - 'A'] = s1[0] - 'A';
- for(int j = 0; j < 26; j++)
- if(C[j] == s2[0] - 'A')C[j] = s1[0] - 'A';
- }
- int n = strlen(s);
- for(int i = 0; i < n; i++){
- if(s[i] == '_')continue;
- s[i] = char(C[s[i] - 'A'] + 'A');
- }
- printf("%s\n", s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment