//其实是一道很水的题,点知道我在没有读懂题意的情况之下,把其做法往深处想了! //注意:You need to expand at most one prefix and one suffix,意思是说只要进行一次前缀和后缀的 //转换即可(要在有前缀和后缀的情况之下啊) #include <iostream> #include <string> #include <map> using namespace std; string pre[5], suf[5]; map<string, string> m; int main() { int i, j, n, pos, prenum; bool flag; string word, tmp, preans, sufans, ans; pre[0] = "anti", pre[1] = "post", pre[2] = "pre", pre[3] = "re", pre[4] = "un"; suf[0] = "er", suf[1] = "ing", suf[2] = "ize", suf[3] = "s", suf[4] = "tion"; m[pre[0]] = "against " , m[pre[1]] = "after ", m[pre[2]] = "before ", m[pre[3]] = " again", m[pre[4]] = "not ", m[suf[0]] = "one who ", m[suf[1]] = "to actively ", m[suf[2]] = "change into ", m[suf[3]] = "multiple instances of ", m[suf[4]] = "the process of "; cin >> n; while (n--){ cin >> word; preans.clear(); sufans.clear(); ans.clear(); flag = false; for (i = 0; i < 5; i++){ pos = word.find(pre[i]); if (pos == 0){ if (i != 3) preans += m[pre[i]]; else{//如果前缀是re的,要记录出现过,到最后再作处理 flag = true; } word.erase(0, pre[i].length()); break; } } for (i = 0; i < 5; i++){ pos = word.rfind(suf[i]); if (pos >= 0 && pos == word.length()-suf[i].length()){ sufans += m[suf[i]]; word.erase(pos, suf[i].length()); if (i == 0) word += "s"; else if (i == 4) word += "ing"; break; } } sufans += word; ans = preans + sufans; if (flag){ ans += " again"; } cout << ans << endl; } system("pause"); }