POJ 2803 Defining Moment(水~)

470 篇文章 3 订阅

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值