UVA10115 - Automatic Editing
# 问题描述
输入一系列的替换规则,然后输入一个字符串,然后在字符串中,寻找相同的字符进行规则转换,直到不能转换后输出。
# 思路
学习string类型,将许多步骤简化封装,从而被更好的利用。
# 代码
#include <iostream>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <string>
using namespace std;
const int N =50;
string s[N],g[N],str;
int main()
{
int i,n;
while(cin>>n&&n)
{
cin.get(); //cin不吃回车
for(i=0;i<n;i++)
{
getline(cin,s[i]);
getline(cin,g[i]);
}
getline(cin,str);
for(i=0;i<n;i++)
{
int found=str.find(s[i],0);
while(found!=-1)
{
str.replace(found,s[i].size(),g[i]);
found=str.find(s[i],0);
}
}
cout<<str<<endl;
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
编辑 (opens new window)
上次更新: 2022/05/18, 19:03:08