Untitled
unknown
c_cpp
2 years ago
1.0 kB
3
Indexable
#include <stdio.h> #include <string.h> int main(){ //id[]存type == 2 時要更換位置的id char s[1000005], a[100005], b[100005], alp[26]; int q, type[100005], id[100005]; long long s2[1000005] = {0};//存字串中哪個位置是type == 2 scanf("%s", s); scanf("%d", &q); int n = strlen(s); for(int i = 0; i < 26; i++){ alp[i] = i + 'a'; } for(int i = 0; i < q; i++){ scanf("%d", &type[i]); if(type[i] == 1){ scanf(" %c %c", &a[i], &b[i]); } else{ scanf("%d %c", &id[i], &b[i]); s[ id[i] ] = b[i]; s2[ id[i] ] = 1; } } for(int i = q - 1; i >= 0; i--){ if(type[i] == 2){ s[ id[i] ] = alp[ b[i] - 'a']; } else{ alp[ a[i] - 'a' ] = alp[ b[i] - 'a']; } } for(int i = 0; i < n; i++){ if(s2[i] == 1) continue; s[i] = alp[ s[i] - 'a' ]; } printf("%s\n", s); }
Editor is loading...