Ctrl + H

Ctrl + H

Time Limit:1000MS  Memory Limit:65536K
Total Submit:345 Accepted:84

Description

As we know, ’Ctrl + H’ is shortcut key of ‘replace’. In the problem, we define the ‘replace’ as replacing one character (all the same character) for another. Now, Junko receives a text and should do some ‘replace’ on it. She has finished the task, do you? 
The text consists of only lowercase English letters. 

Input

Input contains multiple test cases. 
The first line of each test case contains two integer n and m (1 <= n, m < 1000), the length of text, and the number of operation. 
The second line is the text. Next m lines describe the ‘replace’, two letters. 


Output

Print a line, the text after finishing the operation.

Sample Input

4 1
guaa
a b
10 2
javajavaja
a b
b c

Sample Output

gubb
jcvcjcvcjc
题意:给定一个长度为n的字符串和m个操作数,每次操作时将一个字符替换为另外一个字符。

解法:n和m才1000,直接暴力扫一下就可以了。

AC代码:

#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main(){
	int i,j,k,l,n,m,t,ii,a,b;
	char s[1010];
	char o[3],p[3];
	while (cin>>a>>b){
		cin>>s;
		for(i=1;i<=b;i++){
			cin>>o>>p;
			for(j=0;j<a;j++)
				if (s[j]==o[0])s[j]=p[0];
		}
		cout<<s<<endl;
	}
	return 0;
} 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值