1.这题在网上的分类中属于排序部分,但是我怎么做都觉得这就是考 string 的应用
2.坑爹的地方是前缀"re" 所对应的翻译是要在"word"的后方; 后缀"er" 所对应的反应要在原有的"word"的基础上在屁股加"s";“tion” 后要加"ing"
3.最终输出的"word"是去除了前缀跟后缀之后剩下的,题目已经说明了去除之后不会为空的
4.前缀一定是要从第0下标开始; 后缀一定是要从屁股数起
5.先判断前缀,后判断后缀; 而且最多只能有一个前缀跟后缀
6.很无聊的一道题,不过让我练了练string 的函数
#include<iostream>
#include<string>
using namespace std;
int main()
{
int testNum;
cin >> testNum;
while(testNum--)
{
string word;
string prefix, suffix;
cin >> word;
//只找一个前缀
if(word.find("anti") == 0){//能找到"anti"子字符串
prefix = "against ";
word.erase(0, 4);//从下标0开始往后删除4个字符
}
else if(word.find("post") == 0){
prefix = "after ";
word.erase(0, 4);
}
else if(word.find("pre") == 0){
prefix = "before ";
word.erase(0, 3);
}
else if(word.find("re") == 0){
prefix = " again";
word.erase(0, 2);
}
else if(word.find("un") == 0){
prefix = "not ";
word.erase(0, 2);
}
if( word.size() > 2 && word.substr( word.size() - 2 ) == "er" ){
word.erase(word.size() - 2 , 2);//从找到"er"的下标开始删除2个字符
if(prefix != " again")
cout << prefix + "one who " + word + "s" << endl;
else
cout << "one who " + word + "s" + prefix << endl;
}
else if( word.size() > 3 && word.substr( word.size() - 3 ) == "ing" ){
word.erase(word.size() - 3, 3);
if(prefix != " again")
cout << prefix + "to actively " + word << endl;
else
cout << "to actively " + word + prefix << endl;
}
else if(word.size() > 3 && word.substr( word.size() - 3 ) == "ize" ){
word.erase(word.size() - 3, 3);
if(prefix != " again")
cout << prefix + "change into " + word << endl;
else
cout << "change into " + word + prefix << endl;
}
else if(word.size() > 1 && word.substr( word.size() - 1 ) == "s"){
word.erase(word.size() - 1, 1);
if(prefix != " again")
cout << prefix + "multiple instances of " + word << endl;
else
cout << "multiple instances of " + word + prefix << endl;
}
else if(word.size() > 4 && word.substr( word.size() - 4 ) == "tion" )
{
word.erase(word.size() - 4, 4);
if(prefix != " again")
cout << prefix + "the process of " + word + "ing" << endl;
else
cout << "the process of " + word + "ing" + prefix << endl;
}
else//没有后缀
{
if(prefix != " again")
cout << prefix + word << endl;
else
cout << word + prefix << endl;
}
}
return 0;
}