Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
1
Indexable
Never
#include <stdio.h>
#include <string.h>
char str[1000005], alp[30], a1, a2;
int q, op[100005][3], tmp, ok[1000005]; 

int main(){
    scanf("%s %d", str, &q);
    for(int i = 0; i < 26; i++) alp[i] = 'a' + i;
    for(int i= 0; i < q; i++){
        scanf("%d", &op[i][0]);
        if(op[i][0] == 1){
            scanf(" %c %c", &a1, &a2);
            op[i][1] = a1, op[i][2] = a2;
        } 
        else if(op[i][0] == 2){
            scanf("%d %c", &op[i][1], &a1);
            op[i][2] = a1;
        }else if(op[i][0] == 3) scanf("%d %d", &op[i][1], &op[i][2]);
    }
    for(int i = q - 1; i >= 0; i--){
        if(op[i][0] == 1) alp[op[i][1] - 'a'] = alp[op[i][2] - 'a'];
        else if(op[i][0] == 2) op[i][2] = alp[op[i][2] - 'a'];
        else continue;
    }
    for(int i = 0; i < 26; i++) alp[i] = 'a' + i;
    for(int i = 0; i < q; i++){
        if(op[i][0] == 1) alp[op[i][1] - 'a'] = op[i][2];
        else if(op[i][0] == 2) str[op[i][1]] = op[i][2], ok[op[i][1]] = 1;
        else if(op[i][0] == 3){
            tmp = str[op[i][1]], str[op[i][1]] = str[op[i][2]], str[op[i][2]] = tmp;
            tmp = ok[op[i][1]], ok[op[i][1]] = ok[op[i][2]], ok[op[i][2]] = tmp;
        }
    }
    for(int i = 0; str[i] != '\0'; i++){
        if(ok[i] == 0){
            for(int j = 0; j < 26; j++){
                if(str[i] == 'a' + j) str[i] = alp[str[i] - 'a'];
            }
        }
    }
    printf("%s\n", str);
}