Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.3 kB
2
Indexable
Never
#include <stdio.h>

char S[200005];
char X[200005];
char Y[200005];
char N[27]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char M[27]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char x,y;

int main(void){
    int n,m;
    scanf("%d %d",&n,&m);
    scanf("%s",S);
    /*for(int j=0;j<26;j++){
        printf("N[%d]:%c\n",j,N[j]);        
    }*/
    for(int i=0;i<m;i++){
        scanf(" %c %c",&x,&y);
        //if(x==y) continue;
        //printf("%c %c",x,y);
        for(int j=0;j<26;j++){
            if(N[j]==y){
                N[j]=x;
            }
            else if(N[j]==x){
                N[j]=y;
            }
        }
        /*for(int j=0;j<26;j++){
            printf("N[%d]:%c\n",j,N[j]);        
        }*/
    }
    //1
    /*for(int j=0;j<n;j++){
        if(S[j]=='a') S[j]=N[0];
        else if(S[j]=='b') S[j]=N[1];
        else if(S[j]=='c') S[j]=N[2];
        else if(S[j]=='d') S[j]=N[3];
        else if(S[j]=='e') S[j]=N[4];
        else if(S[j]=='f') S[j]=N[5];
        else if(S[j]=='g') S[j]=N[6];
        else if(S[j]=='h') S[j]=N[7];
        else if(S[j]=='i') S[j]=N[8];
        else if(S[j]=='j') S[j]=N[9];
        else if(S[j]=='k') S[j]=N[10];
        else if(S[j]=='l') S[j]=N[11];
        else if(S[j]=='m') S[j]=N[12];
        else if(S[j]=='n') S[j]=N[13];
        else if(S[j]=='o') S[j]=N[14];
        else if(S[j]=='p') S[j]=N[15];
        else if(S[j]=='q') S[j]=N[16];
        else if(S[j]=='r') S[j]=N[17];
        else if(S[j]=='s') S[j]=N[18];
        else if(S[j]=='t') S[j]=N[19];
        else if(S[j]=='u') S[j]=N[20];
        else if(S[j]=='v') S[j]=N[21];
        else if(S[j]=='w') S[j]=N[22];
        else if(S[j]=='x') S[j]=N[23];
        else if(S[j]=='y') S[j]=N[24];
        else if(S[j]=='z') S[j]=N[25];
    }*/
    //2
    for(int i=0;i<n;i++){
        //if(N[i]!=(char)i+97){
            for(int j=0;j<26;j++){
                if(S[i]==M[j]){
                    S[i]=N[j];
                    break;
                }
            }
        //}
    }

    printf("%s\n",S);
    return 0;
}