-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy path10115.cpp
executable file
·50 lines (44 loc) · 1.09 KB
/
10115.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
/* Problem: Automatic Editing UVa 10115
Programmer: Md. Mahmud Ahsan
Description: String + replacing
Compiled: Visual C++ 7.0
Date: 30-08-05
*/
#include <iostream>
#include <string>
using namespace std;
struct dic{
char key[500];
char value[500];
}dics[100];
int main(){
char key[500], value[500], input[1000];
int n, i, j, count;
while (cin >> n){
cin.getline(input, sizeof(input)) ;// eat blank line
if (n == 0) break;
j = 0;
for (i = 0; i < n; ++i){
cin.getline(key, sizeof(key));
cin.getline(value, sizeof(value));
strcpy(dics[j].key, key);
strcpy(dics[j].value, value);
++j;
}
cin.getline(input, sizeof(input));
string buffer(input); // converting char* to string object
for (i = 0; i < n; ++i){//rules are applied
do{
count = 0;
int pos;
while ( (pos = buffer.find(dics[i].key)) != string::npos){
buffer.replace(pos, strlen(dics[i].key), dics[i].value);
++count;
}
if (count == 0) break;//no new match
}while (true);
}
cout << buffer << endl;
}
return 0;
}