-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path回文词.cpp
More file actions
36 lines (35 loc) · 694 Bytes
/
回文词.cpp
File metadata and controls
36 lines (35 loc) · 694 Bytes
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
#include<stdio.h>
#include<string.h>
#include<ctype.h>
const char * rev = "A 3 HIL JM O 2TUVWXY51SE Z 8 ";
const char* msg[] = {"not a palindrome", "a regular palindrome",
"a mirrored string", "a mirrored palindrome"};
char r(char ch){
if(isalpha(ch)){
return rev[ch-'A'];
}
return rev[ch-'0'+25];
}
int main(void){
char s[100];
while(scanf("%s", s) == 1){
int m = 1, p = 1;
int len = strlen(s);
for(int i=0; i<=(len+1)/2; i++){
//判断镜像字符串
if(s[len-i-1] != r(s[i]))
m = 0;
//判断回文字符串
if(s[len-i-1] != s[i])
p = 0;
}
printf("%s -- is %s.\n\n", s, msg[m*2+p]);
}
return 0;
}
/*
NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA
*/