- Notifications
You must be signed in to change notification settings - Fork 117
/
Copy path125.c
64 lines (52 loc) · 1.42 KB
/
125.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
#include<stdio.h>
#include<string.h>
#include<stdbool.h>
charch2lower(charch) {
if (ch >= 'A'&&ch <= 'Z')
ch+=0x20;
returnch;
}
boolisPalindrome(char*s) {
intlen=strlen(s);
inthead, tail;
head=tail=0;
tail=len-1;
while (head <= tail) {
while (ch2lower(s[head]) <'0'
|| (ch2lower(s[head]) >'9'&&ch2lower(s[head]) <'a')
||ch2lower(s[head]) >'z')
{
head++;
if (head>tail) break;
}
while (ch2lower(s[tail]) <'0'
|| (ch2lower(s[tail]) >'9'&&ch2lower(s[tail]) <'a')
||ch2lower(s[tail]) >'z')
{
tail--;
if (head>tail) break;
}
if (head>tail) break;
if (ch2lower(s[head]) !=ch2lower(s[tail])) return false;
head++;
tail--;
}
return true;
}
intmain() {
chars1[] ="A man, a plan, a canal: Panama";
chars2[] ="race a car";
chars3[] ="";
chars4[] ="a";
chars5[] =".,";
chars6[] =".";
chars7[] =" ";
printf("%d\n", isPalindrome(s1));
printf("%d\n", isPalindrome(s2));
printf("%d\n", isPalindrome(s3));
printf("%d\n", isPalindrome(s4));
printf("%d\n", isPalindrome(s5));
printf("%d\n", isPalindrome(s6));
printf("%d\n", isPalindrome(s7));
return0;
}