POJ 2803

题意:字符串翻译,遇到词典库里的前缀和后缀就按照词典库把它改成相应的词语或句子。

View Code
 1 #include<cstdio>

 2 #include<cstring>

 3 #include<algorithm>

 4 using namespace std;

 5 char pre[5][50]={

 6     {"anti"},{"post"},{"pre"},{"re"},{"un"}

 7 };

 8 char pr[5][50]={

 9     {"against "},{"after "},{"before "},{" again"},{"not "}

10 };

11 char suf[5][50]={

12     {"er"},{"ing"},{"ize"},{"s"},{"tion"}

13 };

14 char su[5][50]={

15     {"one who "},{"to actively "},{"change into "},{"multiple instances of "},{"the process of "}

16 };

17 int main()

18 {

19     int T;

20     for(scanf("%d",&T);T;T--)

21     {

22         char s[200],ans[200];

23         scanf("%s",s);

24         int f,r,p=-1,q=-1,len=strlen(s);

25         for(int i=0;i<5;i++)

26         {

27             if(strncmp(pre[i],s,strlen(pre[i]))==0)

28             {

29                 p=i;

30                 break;

31             }

32         }

33         for(int i=0;i<5;i++)

34         {

35             if(strcmp(suf[i],s+len-strlen(suf[i]))==0)

36             {

37                 q=i;

38                 break;

39             }

40         }

41         ans[0]='\0';

42         f=0,r=len;

43         if(p!=-1)

44         {

45             if(p!=3)

46                 strcat(ans,pr[p]);

47             f=strlen(pre[p]);

48         }

49         if(q!=-1)

50         {

51             strcat(ans,su[q]);

52             r=len-strlen(suf[q]);

53         }

54         s[r]='\0';

55         strcat(ans,s+f);

56         if(q==0)

57             strcat(ans,"s");

58         if(q==4)

59             strcat(ans,"ing");

60         if(p==3)

61             strcat(ans,pr[3]);

62         puts(ans);

63     }

64     return 0;

65 }

你可能感兴趣的:(poj)