# 12605 - Rebranding ## 題解: 用模擬的話,最後一筆測資會TLE掉。 用字母表去紀錄互換的字母,最後再一個一個顯示就可以了。 ## Code: ```c=1 #include <stdio.h> #define N 200000 + 5 int n, m; char s[N], x, y; char alpha[] = "abcdefghijklmnopqrstuvwxyz"; int main(){ scanf("%d%d%s", &n, &m, s); for(int i=0; i<m; i++){ scanf(" %c %c", &x, &y); if(x == y) continue; for(int j=0; j<26; j++){ if(alpha[j] == x) alpha[j] = y; else if(alpha[j] == y) alpha[j] = x; } } for(int i=0; i<n; i++) printf("%c", alpha[s[i] - 'a']); printf("\n"); return 0; } ``` ###### tags: `NTHUOJ`