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;
}