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;
}

  

转载于:https://www.cnblogs.com/mjc467621163/archive/2011/07/17/2108642.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值