codeforces 591B - Rebranding(模拟)
来源:互联网 发布:win7注册表优化大全 编辑:程序博客网 时间:2024/05/31 19:00
题目链接:
http://codeforces.com/problemset/problem/591/B
题目大意就是给你一个字符串,给你n行,每行两个字母,表示字符串里这两个字母交换,问你经过n次变换之后的结果是多少。
数据是2*100000,直接暴力的话肯定超时,我的想法是 给你的两个字母 a b 我就默认 a是b,b是a。
AC代码:
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;char s[200035],s1[5],s2[5];int a[30];int main(){ int n,m,i,j,num1,num2; scanf("%d%d",&n,&m); { scanf("%s",s+1); for(i=1;i<=26;i++) a[i]=i; for(i=1;i<=m;i++){ scanf("%s%s",s1,s2); num1=s1[0]-'a'+1; num2=s2[0]-'a'+1; for(j=1;j<=26;j++){ if(a[j]==num1){ a[j]=num2; } else if(a[j]==num2){ a[j]=num1; } } } for(i=1;i<=n;i++){ num1=s[i]-'a'+1; printf("%c",'a'+a[num1]-1); } printf("\n"); }}
0 0
- codeforces 591B - Rebranding(模拟)
- CodeForces-591B Rebranding
- Codeforces 591 B:Rebranding
- codeforces 591B Rebranding
- Codeforces 591B Rebranding
- Codeforces 591B Rebranding
- Codeforces 591B Rebranding
- codeforces round#237,div2,B,Rebranding(模拟)
- codeforces #327 (Div. 2) ->B. 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
- Code Forces 591 B. Rebranding(简单模拟)
- Codeforces Round #327 (Div. 2)B. Rebranding
- Codeforces Round #327 (Div. 2) B. Rebranding
- 九度OJ 1182:统计单词 (计数)
- iOS开发 GitHub 第三方开源库
- ios自动化测试资料
- Android获取图片大小以及获取指定大小的缩略图
- Java 字符终端上获取输入 System.in
- codeforces 591B - Rebranding(模拟)
- Android源码下载
- 在android上实现图像匹配
- android Out of memory on a xxx-byte allocation问题
- Fix iOS 9 App Transport Security Issues In Apache Cordova
- 【SSH】--鸿雁传书,信件发送
- recv
- poj 2625 概率dp
- 九度OJ 1183:守形数 (数字特性)