blob: c8a9a7f80c4e6e0670c2da76a0f5e6215067e2f9 (
plain)
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
|
#include<ctype.h>
#include "stack.h"
int main(void)
{
ElemType ch,a1,a2;
Stack s,p;
int size = 0;
bool flag = false;
InitStack(&s);
InitStack(&p);
while ((ch = getchar()) != '\n')
{
Push(&s,tolower(ch));
size++;
}
if (size == 0)
return 0;
if (size % 2 == 0)
flag = true;
size /= 2;
if (!flag)
size++;
for (int i = 0; i < size; i++)
{
if (flag)
{
Pop(&s,&ch);
Push(&p,ch);
}
else
{
if (i == size - 1)
ch = GetTop(&s);
else
Pop(&s,&ch);
Push(&p,ch);
}
}
while (s)
{
Pop(&s,&a1);
Pop(&p,&a2);
if (a1 != a2)
break;
}
if (s)
{
printf("Not palindrome word!\n");
DestroyStack(&s);
DestroyStack(&p);
}
else
printf("Is palindrome word!\n");
return 0;
}
|