forked from PashaKlybik/prog-053506
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4.1(8).c
76 lines (74 loc) · 1.7 KB
/
4.1(8).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
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <string.h>
#define LONG_STR 80
#define MAX_WORD 40
int Strlen(char *s) {
int pos = 0;
while(s[pos] != '\0') pos++;
return pos;
}
int check(char *a, char b) {
for(int j = 0; j < strlen(a); j++) if(a[j] == b) return 1;
return 0;
}
char *Strcpy(char *str) {
int size = strlen(str);
char *result = malloc((size) * sizeof(char));
for(int i = 0; i < size; i++) {
result[i] = str[i];
}
result[size] = '\0';
return result;
}
char * Strtok(char * str, const char * delim)
{
static char * last = 0;
if (str) {
last = str;
}
if ((last == 0) || (*last == 0)) return 0;
char * c = last;
while(check(delim,*c) == 1) ++c;
if (*c == 0) return 0;
char * start = c;
while(*c && (check(delim,*c)==0)) ++c;
if (*c == 0)
{
last = c;
return start;
}
*c = 0;
last = c+1;
return start;
}
void main(void)
{
char *word[MAX_WORD], separator[] = " ,.?!;:", str[LONG_STR];
int k = 0;
while(1)
{
char* str = malloc(sizeof(char) * LONG_STR);
if(!gets(str)) break;
str[LONG_STR - 1] = '\0';
char *p = strtok(str, separator);
while (p) {
word[k] = Strcpy(p);
k++;
p = strtok(NULL, separator);
}
free(p);
free(str);
}
for (int i = k - 1; i >= 0; i--) {
int good = 1;
int n = Strlen(word[i]);
for(int j = 0; j < n - j - 1; j++) if(word[i][j] != word[i][n - j - 1]) good = 0;
if(good) puts(word[i]);
free(word[i]);
}
return;
}
/*
ab ab ba cdc ede fffff
a aba de d
*/