forked from PashaKlybik/prog-053506
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.2(29).c
63 lines (61 loc) · 1.48 KB
/
5.2(29).c
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
#include<bits.h>
struct node {
char* key;
struct node *l ,*r;
};
struct node* New(){
struct node *v;
v = malloc(sizeof(struct node) * 1);
v -> key = malloc(sizeof(char) * 100);
v -> l = NULL;
v -> r = NULL;
return v;
}
void upd(struct node *v, char* value ){
if(v == NULL) return;
if(strcmp(v -> key, value) > 0) {
if(v -> l == NULL) {
v -> l = New();
strcpy(v -> l -> key, value);
} else upd(v -> l, value);
}
if(strcmp(v -> key, value) < 0) {
if(v -> r == NULL) {
v -> r = New();
strcpy(v -> r -> key, value);
} else upd(v -> r, value);
}
}
char *stak[10000];
int uk = 0;
void Out(struct node *v) {
// puts(v -> key);
if(v -> l != NULL) Out(v -> l);
if(v -> r != NULL) Out(v -> r);
if(v -> l == NULL && v -> r == NULL) {
int cur = 0;
for(int i = 0; i < strlen(v -> key); i++){
cur += (v -> key)[i];
}
if(cur % 2 == 0) {
stak[uk] = malloc(sizeof(char) * strlen(v -> key));
strcpy(stak[uk], (v -> key));
uk++;
}
}
}
int main()
{
struct node *root = New();
char *str = malloc(sizeof(char) * 100);
gets(str);
strcpy(root -> key, str);
while(gets(str)) {
upd(root, str);
}
Out(root);
for(int i = 0; i < uk; i++) {
puts(stak[i]);
free(stak[i]);
}
}