Description
单词的前后缀都有其特殊含义,现在给出一些可能有前后缀的单词以及每个前后缀的含义(如下表),输出经”翻译”后的字符串(每个单词最多有一种前缀和一种后缀)
Input
第一行为一整数T表示用例组数,每组用例占一行为一字符串
Output
对于每组用例,输出翻译后的字符串
Sample Input
6
vaporize
prewar
recooking
root
repopularize
uninforming
Sample Output
change into vapor
before war
to actively cook again
root
change into popular again
not to actively inform
Solution
字符串处理,注意后缀的解释在内部,就是 前缀解释 后缀解释 单词 后缀解释 前缀解释 的形式,注意这个有限顺序,具体看代码
Code
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define maxn 111
char c[maxn];
int f1,f2;
void deal()
{
if(!f1&&c[0]=='a'&&c[1]=='n'&&c[2]=='t'&&c[3]=='i')
{
f1=1;
strcpy(c,c+4);
deal();
return ;
}
if(!f1&&c[0]=='p'&&c[1]=='o'&&c[2]=='s'&&c[3]=='t')
{
f1=2;
strcpy(c,c+4);
deal();
return ;
}
if(!f1&&c[0]=='p'&&c[1]=='r'&&c[2]=='e')
{
f1=3;
strcpy(c,c+3);
deal();
return ;
}
if(!f1&&c[0]=='r'&&c[1]=='e')
{
f1=4;
strcpy(c,c+2);
deal();
return ;
}
if(!f1&&c[0]=='u'&&c[1]=='n')
{
f1=5;
strcpy(c,c+2);
deal();
return ;
}
int l=strlen(c);
if(!f2&&l>=2&&c[l-2]=='e'&&c[l-1]=='r')
{
f2=1;
c[l-2]='\0';
deal();
return ;
}
if(!f2&&l>=3&&c[l-3]=='i'&&c[l-2]=='n'&&c[l-1]=='g')
{
f2=2;
c[l-3]='\0';
deal();
return ;
}
if(!f2&&l>=3&&c[l-3]=='i'&&c[l-2]=='z'&&c[l-1]=='e')
{
f2=3;
c[l-3]='\0';
deal();
return ;
}
if(!f2&&l>=1&&c[l-1]=='s')
{
f2=4;
c[l-1]='\0';
deal();
return ;
}
if(!f2&&l>=4&&c[l-4]=='t'&&c[l-3]=='i'&&c[l-2]=='o'&&c[l-1]=='n')
{
f2=5;
c[l-4]='\0';
deal();
return ;
}
return ;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",c);
f1=f2=0;
deal();
if(f1==1)printf("against ");
else if(f1==2)printf("after ");
else if(f1==3)printf("before ");
else if(f1==5)printf("not ");
if(f2==1)printf("one who ");
if(f2==2)printf("to actively ");
if(f2==3)printf("change into ");
if(f2==4)printf("multiple instances of ");
if(f2==5)printf("the process of ");
printf("%s",c);
if(f2==1)printf("s");
if(f2==5)printf("ing");
if(f1==4)printf(" again");
printf("\n");
}
return 0;
}