CodeForces 591B Rebranding

水题

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std; vector<int> g[];
int n,m;
char s[+],ans[+];
int k[];
char t1[],t2[]; void init()
{
for(int i=; i<; i++) g[i].clear();
} int main()
{
while(~scanf("%d%d",&n,&m))
{
scanf("%s",s);
init();
int len=strlen(s);
for(int i=; i<len; i++)
g[s[i]-'a'].push_back(i);
for(int i=; i<; i++) k[i]=i; for(int i=; i<m; i++)
{
scanf("%s%s",t1,t2);
swap(k[t1[]-'a'],k[t2[]-'a']);
}
for(int i=; i<; i++)
for(int j=; j<g[k[i]].size(); j++)
ans[g[k[i]][j]]='a'+i;
ans[n]='\0';
printf("%s\n",ans);
}
return ;
}
上一篇:【Binary Tree Preorder Traversal】cpp


下一篇:CSS3 :target伪类的理解与使用