/home/toolbox/public_html/solutions/6/673/judged.c
1 #include <stdio.h>
2 #include <strings.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdlib.h>
7
8 #define TRUE (1 == 1)
9 #define FALSE (1 != 1)
10
11 #define DEBUG if (FALSE)
12
13 #define MAX_LINE 150
14
15 /* fprintf(stderr, "functionName: message", varslist); */
16
17 /*
18 * Author: Practice
19 * Date: 2005 08 10
20 * Purpose: practice
21 * Problem: 673
22 */
23
24 /*
25 * This template reads data a specified number of times.
26 */
27
28 int numberOfTimes;
29 char line[MAX_LINE];
30
31 int init()
32 {
33 /* FUNCTION init */
34 fgets(line, MAX_LINE, stdin);
35 sscanf(line, " %d ", &numberOfTimes);
36 } /* FUNCTION init */
37
38 void dump()
39 {
40 /* FUNCTION dump */
41 } /* FUNCTION dump */
42
43 void getInput()
44 {
45 /* FUNCTION getInput */
46 int i = 0;
47
48 line[i] = fgetc(stdin);
49 while ('\n' != line[i])
50 {
51 DEBUG printf("%c", line[i]);
52 i++;
53 line[i] = fgetc(stdin);
54 }
55 line[i] = '\0';
56 } /* FUNCTION getInput */
57
58 int clean(char open, char close)
59 {
60 char *r;
61 int i, t;
62 int len;
63 int flagman = FALSE;
64
65 DEBUG printf("ForStarters!%s!\n", line);
66
67
68 if (0 == strlen(line))
69 {
70 r = NULL;
71 }
72 else
73 {
74 r = strchr(&line[1], close);
75 }
76 while (NULL != r)
77 {
78 t = r - line - 1;
79 DEBUG printf("t = %d line[t] = %c\n", t, line[t]);
80 if (open == line[t])
81 {
82 flagman = TRUE;
83 len = strlen(line);
84
85 t = r - line;
86
87 DEBUG printf("$%s$ t = %d len = %d\n", line, t, len);
88
89 for (i = t; i < len; i++)
90 {
91 line[i - 1] = line[i + 1];
92 }
93 r = strchr(&line[1], close);
94 }
95 else
96 {
97 r = NULL;
98 }
99 DEBUG printf("HAH!%s!\n", line);
100 }
101 return flagman;
102 }
103
104 void process()
105 {
106 /* FUNCTION process */
107 int flag = TRUE;
108
109 while (flag == TRUE)
110 {
111 flag = clean('[', ']');
112 flag = flag || clean('(', ')');
113 }
114
115 DEBUG printf("!%s!\n", line);
116 if (0 == strlen(line))
117 {
118 printf("Yes\n");
119 }
120 else
121 {
122 printf("No\n");
123 }
124
125 } /* FUNCTION process */
126
127 int main ()
128 {
129 /* main */
130 int i;
131
132 init();
133 for (i=0; i<numberOfTimes; i++)
134 {
135 /* while */
136 getInput();
137 process();
138 } /* while */
139
140 return EXIT_SUCCESS;
141 } /* main */
142