给一字符串,每次操作把字符串中的两种字母交换,问最后交换完的字符串是多少
arr数组记录每个字母最后被替换成了哪个字母
读入字符前面加一空格 scanf(" %c %c", &a, &b); 
#include <iostream>
#include <cstdio>
using namespace std;
#define SZ 200005
char c[SZ];
int main()
{
int n, m;
int arr[];
scanf("%d %d", &n, &m);
char a, b;
scanf(" %s", c);
int len = strlen(c);
for(int i = ; i < ; i++)
arr[i] = i;
for(int i = ; i < m; i++)
{
scanf(" %c %c", &a, &b);
int aa = a - 'a', bb = b - 'a', p, q;
for(int j = ; j < ; j++) if(arr[j] == aa) {p = j; break;}
for(int j = ; j < ; j++) if(arr[j] == bb) {q = j; break;}
arr[p] = bb;
arr[q] = aa;
}
for(int j = ; j < len; j++)
{
c[j] = arr[c[j] - 'a'] + 'a';
}
printf("%s\n", c);
return ;
}

字符串 || CodeForces 591B Rebranding的更多相关文章

  1. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

  2. CodeForces 591B Rebranding

    水题 #include<cstdio> #include<cstring> #include<cmath> #include<vector> #incl ...

  3. CodeForces 591B

    题目链接: http://codeforces.com/problemset/problem/591/B 题意: 给你一串字符串,字符串里的字符全是a-z的小写字母,下面的m行,是字符串的交换方式, ...

  4. Codeforces Round #327 (Div2) A~E

    CodeForces 591A 题意:在距离为L的两端A,B,相向发射魔法,a(以P1的速度)-->B,A<--b(以P2的速度).假设a-->B,途中相遇,则返回到原点A<- ...

  5. 多项式模板&题目整理

    注:多项式的题目,数组应开:N的最近2的整数次幂的4倍. 多项式乘法 FFT模板 时间复杂度\(O(n\log n)\). 模板: void FFT(Z *a,int x,int K){ static ...

  6. codeforces 723B Text Document Analysis(字符串模拟,)

    题目链接:http://codeforces.com/problemset/problem/723/B 题目大意: 输入n,给出n个字符的字符串,字符串由 英文字母(大小写都包括). 下划线'_' . ...

  7. Codeforces 176B (线性DP+字符串)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28214 题目大意:源串有如下变形:每次将串切为两半,位置颠倒形成 ...

  8. Codeforces Round #309 (Div. 2) B. Ohana Cleans Up 字符串水题

    B. Ohana Cleans Up Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/554/pr ...

  9. Codeforces Round #309 (Div. 2) A. Kyoya and Photobooks 字符串水题

    A. Kyoya and Photobooks Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

随机推荐

  1. 【旧文章搬运】炉子给的SYSTEM_HANDLE_TYPE有点错误

    原文发表于百度空间,2008-12-03========================================================================== 今天写程序 ...

  2. Java中手动提交事务

    项目中遇到一个问题,就是在程序的执行过程中需要不断地更新某个信息,但是在springmvc中好像是默认不可以的,那么就需要手动提交 // 从spring容器对象中获取DataSourceTransac ...

  3. grep在指定类型的文件中查找字符 (转载)

    转自:http://blog.csdn.net/qvbfndcwy/article/details/8127329 find -name '*.php'|xargs grep 'include'//在 ...

  4. SCUT - 240 - 宝华的文件系统 - 模拟

    https://scut.online/p/240 就是要小心绝对路径中也有.和..出现. #include<bits/stdc++.h> using namespace std; #de ...

  5. go语言 rsa加密

    // rsa.go package main import ( "crypto/rand" "crypto/rsa" "crypto/x509&quo ...

  6. Unity局部高效实时阴影的思考和实现

    http://game.ceeger.com/forum/read.php?tid=23305&fid=2 无意间看到一篇文章,说是Unity5 demo中为了实现角色的良好阴影,单独给角色设 ...

  7. WPF DataGrid foreground 绑定问题

    初学WPF ,  希望对DataGrid 中所属的一个Column名下的值的颜色动态修改 <DataGridTextColumn Header="隐含回购利率(%)" Bin ...

  8. 给Clouderamanager集群里安装可视化分析利器工具Hue步骤(图文详解)

    扩展博客 以下,是我在手动的CDH版本,安装Hue. CDH版本大数据集群下搭建Hue(hadoop-2.6.0-cdh5.5.4.gz + hue-3.9.0-cdh5.5.4.tar.gz)(博主 ...

  9. hdu1102 Constructing Roads 基础最小生成树

    //克鲁斯卡尔(最小生成树) #include<cstdio> #include<iostream> #include<algorithm> using names ...

  10. iOS 优雅地隐藏导航栏NavigationBar (Objc)

    @interface FSViewController () <UINavigationControllerDelegate> @end @implementation FSViewCon ...