BoxerTC

Untitled

Jun 28th, 2015
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3. #define N 1000005
  4.  
  5. using namespace std;
  6.  
  7. char s[N], s1[2], s2[N];
  8. int C[N];
  9.  
  10. int main(){
  11.    
  12.     int tc = 0;
  13.     scanf("%d", &tc);
  14.    
  15.     while(tc--){
  16.    
  17.         scanf("%s", s);
  18.         int m;
  19.        
  20.         scanf("%d", &m);
  21.         for(int i = 0; i < 26; i++)C[i] = i;
  22.        
  23.         for(int i = 0; i  < m; i++){
  24.            
  25.             scanf("%s%s", s1, s2);
  26.             C[s2[0] - 'A'] = s1[0] - 'A';
  27.            
  28.             for(int j = 0; j < 26; j++)
  29.                 if(C[j] == s2[0] - 'A')C[j] = s1[0] - 'A';     
  30.         }
  31.        
  32.         int n = strlen(s);
  33.         for(int i = 0; i < n; i++){
  34.            
  35.             if(s[i] == '_')continue;
  36.             s[i] = char(C[s[i] - 'A'] + 'A');
  37.         }
  38.        
  39.         printf("%s\n", s);
  40.     }
  41.    
  42. }
Advertisement
Add Comment
Please, Sign In to add comment