Remove markup
1 #include <stdio.h>
2 /* by Michal Koucky */
3 /* Used linear method - you count the number of expected 'enclosed'
4 expressions. After every operator E,... you expect one more expression
5 than before, N doesn't change the number of expected expressions,
6 p through z decreases the number of expected expressions by one (they
7 are enclosed expr). */
8
9 int read_sen()
10 /**
11 r: 0 ok.
12 -1 syntax err
13 -3 eof
14 */
15 {
16 char c;
17 int senc; /* number of expected (sub)sentences */
18
19 senc=1; /* you expect one enclosed expression */
20
21 while(1){
22
23 switch( c= getchar() )
24 {
25
26 case 'C':
27 case 'D':
28 case 'E':
29 case 'I':
30 if(senc)senc++;
31 case 'N':
32 if(!senc){ /* consume rest of line */
33 while(getchar()!='\n');
34 return -1;
35 }
36 break;
37
38 case '\n':
39 if(senc) return -1;
40 else return 0;
41 case EOF:
42 return -3;
43 default:
44 if( c < 'p' || c > 'z' || !senc){ /* consume rest of line */
45 while(getchar()!='\n');
46 return -1;
47 }
48 senc--;
49 }
50 }
51 return -1;
52 }
53
54 int main()
55 {
56 while(1)
57 {
58 switch(read_sen())
59 {
60 case 0:
61 printf("YES\n");
62 break;
63 case -1:
64 printf("NO\n");
65 break;
66 case -3:
67 return 0;
68 }
69 }
70 } /* main */
71
syntax highlighted by Code2HTML, v. 0.9.1