---
# System prepended metadata

title: 13573 - String Operations 2
tags: [string]

---

# 	13573 - String Operations 2

>author: Utin
###### tags: `string`

---

## Brief
需建表以免TLE
String Operation目前已知共有4種變化
13572 String Operations 1
13573 String Operations 2
13692 Aftermath’s Ideology
13805 Professor Bear’s Challenge

## Solution 0

```c=
#include <stdio.h>
#include <string.h>

int Q;
char arr[1000001]; // input
char table[100001][26]; // alphabet table
int op[100001][3]; // operation queue

int main() {
    scanf("%s", arr);
    scanf("%d", &Q);

    int len = strlen(arr);

    for (int i = 0; i < 26; i++) table[Q][i] = 'a' + i;

    // input
    for (int q = 0; q < Q; q++) {
        scanf("%d", &op[q][0]);
        if (op[q][0] == 1) {
            char temp1, temp2;
            scanf(" %c %c", &temp1, &temp2);
            op[q][1] = temp1;
            op[q][2] = temp2;
        }
        else if (op[q][0] == 2) {
            char temp;
            scanf("%d %c", &op[q][1], &temp);
            op[q][2] = temp;
        }
    }

    // operation type 1
    for (int q = Q-1; q >= 0; q--) {
        // update
        for (int i = 0; i < 26; i++) {
            table[q][i] = table[q+1][i];
        }
        if (op[q][0] == 1) {
            table[q][op[q][1]-'a'] = table[q+1][op[q][2]-'a'];
        }
    }

    for (int q = 0; q < Q; q++) {
        // operation type 2
        if (op[q][0] == 2) {
            arr[op[q][1]] = table[q][op[q][2]-'a'] - 32;
        }
    }

    // output
    for (int i = 0; i < len; i++) {
        if (arr[i] >= 'a') printf("%c", table[0][arr[i]-'a']);
        else printf("%c", arr[i] + 32);
    }
    printf("\n");
}
// By Utin
```

## Reference