URAL 1102. Strange Dialog

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1102

正着做9种情况:

in

input

inputon

inputone

out

output

outputon

outputone

one

反着做貌似更简单一些,情况更少一点。

我是正着做的。

 1 #include <cstdio>

 2 

 3 const int MAXN = 10000000 + 5;

 4 

 5 char str[MAXN];

 6 

 7 bool Judge()

 8 {

 9     if ( !(str[0] == 'o' || str[0] == 'p' || str[0] == 'i') ) return false;

10     int i = 0;

11     while ( str[i] != '\0' )

12     {

13         switch( str[i] )

14         {

15         case 'o':

16             if ( str[i+1] == 'u' && str[i+2] == 't' )

17             {

18                 if ( str[i+3] == 'p' && str[i+4] == 'u' && str[i+5] == 't' )

19                 {

20                     if ( str[i+6] == 'o' && str[i+7] == 'n' )

21                     {

22                         i += 8;

23                         if ( str[i] == 'e' ) ++i;

24 

25                     }

26                     else i += 6;

27                 }

28                 else i += 3;

29             }

30             else if ( str[i+1] == 'n' && str[i+2] == 'e' )

31                 i += 3;

32             else return false;

33             break;

34         case 'i':

35             if ( str[i+1] == 'n' )

36             {

37                 if ( str[i+2] == 'p' && str[i+3] == 'u' && str[i+4] == 't' )

38                 {

39                     if ( str[i+5] == 'o' && str[i+6] == 'n' )

40                     {

41                         i += 7;

42                         if ( str[i] == 'e' ) ++i;

43                     }

44                     else i += 5;

45                 }

46                 else i += 2;

47             }

48             else return false;

49             break;

50         case 'p':

51             if ( str[i+1] == 'u' && str[i+2] == 't' && str[i+3] == 'o' && str[i+4] == 'n' ) i += 5;

52             else return false;

53             break;

54         default :return false;

55         }

56     }

57     return true;

58 }

59 

60 int main()

61 {

62     int n;

63     scanf( "%d", &n );

64     while ( n-- )

65     {

66         scanf( "%s", str );

67         if ( Judge() ) puts("YES");

68         else puts("NO");

69     }

70     return 0;

71 }

你可能感兴趣的:(dialog)