sicily 1252. Defining Moment

#include<iostream>        //字符串模拟题
#include<string>
using namespace std;
string str;
int st,ed;
bool fit(int i,int j,string ss)
{
if(i<st||j>ed)
return false;
for(int k=0;k<=j-i;++k)
if(str[k+i]!=ss[k])
return false;
return true;
}
int main()
{
int cases;
cin
>>cases;
while(cases--)
{
string res;
cin
>>str;
st
=0;ed=str.size()-1;
int tag;

//前缀
if(fit(0,3,"anti"))
{
tag
=1;
res
="against ";
st
+=4;
}
else if(fit(0,3,"post"))
{
tag
=1;
res
="after ";
st
+=4;
}
else if(fit(0,2,"pre"))
{
tag
=1;
res
="before ";
st
+=3;
}
else if(fit(0,1,"re"))
{
tag
=2;
res
=" again";
st
+=2;
}
else if(fit(0,1,"un"))
{
tag
=1;
res
="not ";
st
+=2;
}
else
{
tag
=0;
}

//后缀
if(fit(ed-1,ed,"er"))
{
if(tag==0)
res
="one who "+str.substr(0,ed-2+1)+"s";
else if(tag==1)
res
=res+"one who "+str.substr(st,ed-2-st+1)+"s";
else
res
="one who "+str.substr(st,ed-2-st+1)+"s"+res;
}
else if(fit(ed-2,ed,"ing"))
{
if(tag==0)
res
="to actively "+str.substr(0,ed-3+1);
else if(tag==1)
res
=res+"to actively "+str.substr(st,ed-3-st+1);
else
res
="to actively "+str.substr(st,ed-3-st+1)+res;
}
else if(fit(ed-2,ed,"ize"))
{
if(tag==0)
res
="change into "+str.substr(0,ed-3+1);
else if(tag==1)
res
=res+"change into "+str.substr(st,ed-3-st+1);
else
res
="change into "+str.substr(st,ed-3-st+1)+res;
}
else if(fit(ed,ed,"s"))
{
if(tag==0)
res
="multiple instances of "+str.substr(0,ed-1+1);
else if(tag==1)
res
=res+"multiple instances of "+str.substr(st,ed-1-st+1);
else
res
="multiple instances of "+str.substr(st,ed-1-st+1)+res;
}
else if(fit(ed-3,ed,"tion"))
{
if(tag==0)
res
="the process of "+str.substr(0,ed-4+1)+"ing";
else if(tag==1)
res
=res+"the process of "+str.substr(st,ed-4-st+1)+"ing";
else
res
="the process of "+str.substr(st,ed-4-st+1)+"ing"+res;
}
else
{
if(tag==0)
res
=str;
else if(tag==1)
res
=res+str.substr(st,ed-st+1);
else
res
=str.substr(st,ed-st+1)+res;
}


cout
<<res<<endl;
}
return 0;
}

  

posted on 2011-07-17 11:40  sysu_mjc  阅读(157)  评论(0编辑  收藏  举报

导航