-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10115.cpp
53 lines (48 loc) · 1.04 KB
/
P10115.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
typedef pair<string,string> PP;
typedef vector<PP> Vector;
unsigned int readUInt() {
unsigned int ret = 0;
char w[20];
gets(w);
for(int i = 0; i < 20; ++i) {
if(!(w[i] >= '0' && w[i] <= '9'))
break;
ret = ret * 10 + (w[i]-'0');
}
return ret;
}
int main() {
char line[300];
while(true) {
int rules = readUInt();
if(rules == 0)
return 0;
Vector v;
for(int i = 0; i < rules; ++i) {
gets(line);
string s1(line);
gets(line);
string s2(line);
v.push_back(PP(s1,s2));
}
gets(line);
string s(line);
// Handle line:
for(unsigned int ruleI = 0; ruleI < v.size(); ++ruleI) {
string from = v[ruleI].first, to = v[ruleI].second;
int start = 0;
while((start = s.find(from, start)) != (int)string::npos) {
s.replace(start, from.length(), to);
start -= from.length()+1;
if(start < 0)
start = 0;
}
}
cout << s << endl;
}
}