码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #327 (Div. 2) B Rebranding

时间:2015-10-26 00:30:30      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

做映射,最后一次性替换。

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int LEN = 2e5+5;
char s[LEN];
char mp[26];
int pos[26];
//#define LOCAL
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    for(int i = 0; i < 26; i++) pos[i] = i;
    int n, m; scanf("%d%d%s",&n,&m,s);
    while(m--){
        char x[2], y[2]; scanf("%s %s", x, y);
        swap(pos[*x-a], pos[*y-a]);
    }
    for(int i = 0; i < 26; i++) mp[pos[i]] = i+a;
    for(int i = 0; i < n; i++) putchar(mp[s[i]-a]);
    return 0;
}

 

Codeforces Round #327 (Div. 2) B Rebranding

标签:

原文地址:http://www.cnblogs.com/jerryRey/p/4909922.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!