方法一:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#define max_num 100
bool ModeJudgment(char str1[], char str2[]) {
if (strlen(str1) != strlen(str2)) {
return false;
}
int len = strlen(str1);
char* ptail = str1 + len - 1;
char* phead = str2;
while (*phead != '\0') {
if (*phead != *ptail) {
return false;
}
phead++;
ptail--;
}
return true;
}
int main() {
char str1[max_num] = { '\0' };
char str2[max_num] = { '\0' };
char c;
int len1 = 0, len2 = 0;
while (scanf("%c", &c) && (c-'&') != 0) {
str1[len1++] = c;
}
scanf("&");//处理两个字符间的间隔符
while (scanf("%c", &c) && (c - '@') != 0) {
str2[len2++] = c;
}
if (ModeJudgment(str1, str2)) {
printf("True\n");
}
else {
printf("False\n");
}
//printf("%s\n%s", str1, str2);
return 0;
}
方法二:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#define max_num 100
bool ModeJudgment(char* str) {
int len = strlen(str);
char* ptail = str + len - 2;
char* phead = str;
while (*phead != '&'&& *ptail!='&') {
if (*phead != *ptail) {
return false;
}
phead++;
ptail--;
}
if (*phead == '&' && *ptail == '&') {
return true;
}
return false;//前后两条链不一样长的情况
}
int main() {
char str[max_num] = { '\0' };
scanf("%s", str);
if (ModeJudgment(str)) {
printf("True\n");
}
else {
printf("False\n");
}
return 0;
}