Codeforces 591B Rebranding
来源:互联网 发布:linux的uniq 编辑:程序博客网 时间:2024/05/02 08:48
题目链接:http://codeforces.com/problemset/problem/591/B
题 意:给你一个字符数组级数组内字母的变化方式,问变化后的数组是什么。
题 意:不可暴力,会超时。
要将26个字母用1~26编号并存入数组,再将每两个要交换的字母的对应编号交换,最后将每个字母变换后的字母存入另一个数组,再在这个数组内找到要求的字符数组的每一个字符变换后的字母并输出。
代码如下:
#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <stack>using namespace std;typedef __int64 LL;char str[200006];int main(){ int l, n; while( scanf ( "%d %d", &l, &n ) != EOF ) { scanf ( "%s", str ); int a[26], b[26]; for( int i = 0; i < 26; i ++ ) a[i] = i;//开始时每一个字母对应的编号a~z for( int i = 0; i < n; i ++ ) { char x, y; scanf ( " %c %c", &x, &y ); int xx = x - 'a'; int yy = y - 'a'; int t = a[xx];//编号交换 a[xx] = a[yy]; a[yy] = t; } for( int i = 0; i < 26; i ++ ) b[ a[i] ] = i;//a[i]即是第i个字母变换后对应的字母 for( int i = 0; i < l; i ++ ) { str[i] = b[ str[i] - 'a' ] + 'a';//找对应的字母 } puts(str); } return 0;}
1 0
- CodeForces-591B Rebranding
- Codeforces 591 B:Rebranding
- codeforces 591B Rebranding
- Codeforces 591B Rebranding
- Codeforces 591B Rebranding
- Codeforces 591B Rebranding
- codeforces 591B - Rebranding(模拟)
- Codeforces 591 B Rebranding【Codeforces Round #327 (Div. 2)】
- Codeforces #327-B. Rebranding-hash
- coderforce 591B Rebranding
- cf 591B Rebranding
- CF 591B Rebranding
- cordeforce 591 B. Rebranding
- Codeforces Round #327 (Div. 2)B. Rebranding
- Codeforces Round #327 (Div. 2) B. Rebranding
- Codeforces Round #327 (Div. 2) B. Rebranding
- Codeforces Round #327 (Div. 2)B. Rebranding
- Codeforces Round #327 (Div. 2)B. Rebranding
- 基于xubutun虚拟机下使用git下载bitcraze github中的文件
- 给Source Insight做个外挂系列之二--将本地代码注入到Source Insight进程
- 给Source Insight做个外挂系列之三--构建外挂软件的定制代码框架
- Android权限机制总结与常见权限不足问题分析
- 通过继承ListActivity实现列表
- Codeforces 591B Rebranding
- 给Source Insight做个外挂系列之四--分析“Source Insight”
- [kuangbin带你飞]专题一 简单搜索 A - 棋盘问题 poj1321
- [桌面版] 在 Mockplus 2.1 (预览版)中使用滚动区
- 国内O365和国外O365的区别
- 给Source Insight做个外挂系列之五--Insight “TabSiPlus”
- Testing Round #12 (597A,597B,597C)
- 整数划分问题
- 给Source Insight做个外挂系列之六--“TabSiPlus”的其它问题