nelson33

Untitled

Oct 30th, 2022
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. char str[1000005],change[100005],change2[100005];
  4. int type[100005],detect[1000005],id[1000005];
  5. int  main(){
  6.     gets(str);
  7.     int len=strlen(str);
  8.     int Q;
  9.     for(int i=0;i<len;i++) detect[i]=0;
  10.     scanf("%d",&Q);
  11.     char table[26];
  12.     for(int i=0;i<26;i++){
  13.         table[i] = 'a' + i;
  14.     }
  15.     for(int i=0;i<Q;i++){
  16.         scanf("%d",&type[i]);
  17.         int c1,c2;
  18.         if(type[i]==2){
  19.             scanf(" %d %c",&c1,&c2);
  20.             id[i]=c1;
  21.             change[i]=c2;
  22.         }
  23.         if(type[i]==1){
  24.             scanf(" %c %c",&c1,&c2);
  25.             change[i]=c1;
  26.             change2[i]=c2;
  27.         }
  28.     }
  29.     for(int i =Q-1;i>-1;i--){
  30.         if(type[i] ==2){
  31.             if(detect[id[i]] ==0){
  32.                 str[id[i]] =change2[i];
  33.                 detect[id[i]] =1;
  34.             }          
  35.         }
  36.         if(type[i]==1){
  37.             int temp2=change[i]-'a';
  38.             int temp3=change2[i]-'a';
  39.             table[temp2]=table[temp3];
  40.         }
  41.     }  
  42.     for(int i=0;i<len;i++) printf("%c",table[str[i]-'a']);
  43.     printf("\n");
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment