zoukankan      html  css  js  c++  java
  • cf591B Rebranding

    B. Rebranding
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.

    For this purpose the corporation has consecutively hired m designers. Once a company hires the i-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters xiby yi, and all the letters yi by xi. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that xi coincides with yi. The version of the name received after the work of the last designer becomes the new name of the corporation.

    Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive.

    Satisfy Arkady's curiosity and tell him the final version of the name.

    Input

    The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the length of the initial name and the number of designers hired, respectively.

    The second line consists of n lowercase English letters and represents the original name of the corporation.

    Next m lines contain the descriptions of the designers' actions: the i-th of them contains two space-separated lowercase English lettersxi and yi.

    Output

    Print the new name of the corporation.

    Sample test(s)
    input
    6 1
    police
    p m
    output
    molice
    input
    11 6
    abacabadaba
    a b
    b c
    a d
    e g
    f a
    b b
    output
    cdcbcdcfcdc
    Note

    In the second sample the name of the corporation consecutively changes as follows:

     

    记一下每个字母的映射怎么变就好了

     1 #include<set>
     2 #include<map>
     3 #include<cmath>
     4 #include<ctime>
     5 #include<deque>
     6 #include<queue>
     7 #include<bitset>
     8 #include<cstdio>
     9 #include<cstdlib>
    10 #include<cstring>
    11 #include<iostream>
    12 #include<algorithm>
    13 #define LL long long
    14 #define inf 0x7fffffff
    15 #define pa pair<int,int>
    16 #define pi 3.1415926535897932384626433832795028841971
    17 using namespace std;
    18 inline LL read()
    19 {
    20     LL x=0,f=1;char ch=getchar();
    21     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    22     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    23     return x*f;
    24 }
    25 int n,m,a,b,x,y,go[30];
    26 char ch[1000010];
    27 char c,d;
    28 int main()
    29 {
    30     n=read();m=read();
    31     scanf("%s",ch+1);
    32     for (int i=1;i<=26;i++)go[i]=i;
    33     for (int i=1;i<=m;i++)
    34     {
    35         cin>>c>>d;
    36         a=c-'a'+1;
    37         b=d-'a'+1;
    38         for (int j=1;j<=26;j++)
    39         {
    40             if (go[j]==a)x=j;
    41             if (go[j]==b)y=j;
    42         }
    43         swap(go[x],go[y]);
    44     }
    45     for (int i=1;i<=n;i++)printf("%c",(char)(go[ch[i]-'a'+1]+'a'-1));
    46 }
    cf591B
    ——by zhber,转载请注明来源
  • 相关阅读:
    bootstrap:按钮,下拉菜单
    js:indexOf()方法
    js:object.offsetHeight属性
    css y轴溢出滚动条,x轴溢出显示
    datatables使用方式
    ajax同步与异步的坑
    IntelliJ IDEA 快捷键说明大全(中英对照、带图示详解) (转载)
    无法解析此远程名称: 'www.***.com' 解决办法 请求因 HTTP 状态 417 失败 (转载)
    Windows下安装MongoDB3.6.5 (转载)
    解决内部存储空间紧张,不加载桌面壁纸,桌面壁纸显示
  • 原文地址:https://www.cnblogs.com/zhber/p/4926552.html
Copyright © 2011-2022 走看看