-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp204.c
More file actions
68 lines (47 loc) · 858 Bytes
/
p204.c
File metadata and controls
68 lines (47 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* https://www.aceptaelreto.com/problem/statement.php?id=204
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
count_branch(char* buff, int* adornos, int* pos) {
int elm = 0;
int ad[2] = {0,0};
*pos = *pos + 1;
while (elm < 2) {
if (buff[*pos] == 'Y') {
if (!count_branch(buff, &ad[elm], pos))
return 0;
elm++;
continue;
}
if (buff[*pos] == '*') {
ad[elm] = 1;
}
elm++;
*pos = *pos + 1;
}
*adornos = ad[0] + ad[1];
if (abs(ad[0] - ad[1]) >= 2)
return 0;
return 1;
}
int
main(int argc, char**argv) {
int adornos;
int pos;
char buff[100001];
while (fgets(buff, 100001, stdin)) {
pos = 0;
if (buff[0] == '.' || buff[0] == '*') {
printf("OK\n");
continue;
}
if (count_branch(buff, &adornos, &pos))
printf("OK\n");
else
printf("KO\n");
}
return 0;
}