UVa 10115 Automatic Editing

/* coder: ACboy date: 2010-2-16 result: AC description: UVa 10115 Automatic Editing */ #include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std; vector<string> findve; vector<string> replaceve; // 查找字符串a中是否存在find字串, // 如果存在find则返回find出现的第一个位置, // 如果不存在则返回-1。 /*int findstr(string &a, string &find) { int position = -1; int len = a.size(); int findlen = find.size(); for (int i = 0; i < len - findlen; i++) { if (find == a.substr(i, findlen)) { position = i; break; } } return position; }*/ int main() { int n; int i; #ifndef ONLINE_JUDGE freopen("10115.txt", "r", stdin); #endif while (cin >> n) { string k; if (n == 0) break; else { getline(cin, k); for (i = 0; i < n; i++) { string temp; getline(cin, temp); findve.push_back(temp); getline(cin, temp); replaceve.push_back(temp); } string str; getline(cin, str); for (i = 0; i < n; i++) { // 当在str中没有找到时返回string::npos值为负一(-1)。 int position = str.find(findve[i]); while (position != -1) { str.replace(position, findve[i].size(), replaceve[i]); position = str.find(findve[i]); } } cout << str << endl; findve.clear(); replaceve.clear(); } } return 0; }

你可能感兴趣的:(UVa 10115 Automatic Editing)