-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path401.c
52 lines (47 loc) · 1.39 KB
/
401.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define PALINDROM 0x1
#define MIRROR 0x2
const char * const mirror = "1SE\000Z\000\0008\000\000\000\000\000\000\000\000A"
"\000\000\0003\000\000HIL\000JM\000O\000\000\0002TU"
"VWXY5";
int main(int argc, char const *argv[])
{
char line[0xFF];
int state;
char *p1, *p2;
while(fgets(line, 0xFF, stdin))
{
if(line[strlen(line) - 1] == '\n')
line[strlen(line) - 1] = '\0';
state = PALINDROM | MIRROR;
p1 = &line[0];
p2 = &line[strlen(line) - 1];
for(; p2 >= p1; ++p1, --p2)
{
if(state == 0)
break;
if(*p1 != *p2)
state &= ~PALINDROM;
if(*p1 != mirror[*p2 - '1'])
state &= ~MIRROR;
}
printf("%s", line);
switch (state) {
case 0:
printf("%s\n\n", " -- is not a palindrome.");
break;
case PALINDROM:
printf("%s\n\n", " -- is a regular palindrome.");
break;
case MIRROR:
printf("%s\n\n", " -- is a mirrored string.");
break;
case PALINDROM | MIRROR:
printf("%s\n\n", " -- is a mirrored palindrome.");
break;
}
}
return 0;
}