Codeforces Round #327 (Div. 2) B Rebranding(映射)

O(1)变换映射,最后一次性替换。

#include<bits/stdc++.h>
using namespace std; typedef long long ll; const int LEN = 2e5+;
char s[LEN];
char mp[];
int pos[];
//#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
for(int i = ; i < ; i++) pos[i] = i;
int n, m; scanf("%d%d%s",&n,&m,s);
while(m--){
char x[], y[]; scanf("%s %s", x, y);
swap(pos[*x-'a'], pos[*y-'a']);
}
for(int i = ; i < ; i++) mp[pos[i]] = i+'a';
for(int i = ; i < n; i++) putchar(mp[s[i]-'a']);
return ;
}
上一篇:安装PHP的mongodb驱动速记


下一篇:海量数据挖掘MMDS week2: 局部敏感哈希Locality-Sensitive Hashing, LSH