签到题。思想类似线段树懒操作。
#include<cstdio> #include<cstring> const int maxlen = 1000000+10; char str[maxlen]; char to[256]; int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int T; scanf("%d",&T); to[‘_‘] = ‘_‘; while(T--){ scanf("%s",str); int e; scanf("%d\n",&e); for(int i = ‘A‘; i <= ‘Z‘; i++) to[i] = i; for(int j = 0; j < e; j++){ int v,u; char buf[10]; fgets(buf,9,stdin); int i = 0; for(;i<9;i++) if(‘A‘<=buf[i]&&buf[i]<=‘Z‘){ v = buf[i++]; break; } for(;i<9;i++) if(‘A‘<=buf[i]&&buf[i]<=‘Z‘){ u = buf[i++] ; break; } for(int i = ‘A‘; i <= ‘Z‘;i++){ if(u == to[i]) to[i] = v; } } int len = strlen(str); for(int i = 0; i < len; i++){ str[i] = to[str[i]]; } printf("%s\n",str); } return 0; }
原文:http://www.cnblogs.com/jerryRey/p/4652486.html