#include<stdio.h> #define STRLEN 100 int Is_palindromic_str(char *str) { int left = 0;//字符串数组的第一个字母的下标 int i = 0; while(str[i] != '\0') { i++; } int right = i - 1;//字符串数组最后一个字母(非‘\0’)的下标 while(left <= right) { if(str[left] == str[right])//判断左右字符是否一致,一致的话判断下一个 { left++; right--; } else return -1;//不一致,表明不是回文数字符串 } return 1; } int main() { char str[STRLEN]; int i = 1; //循环控制的条件 while(i) { printf("Please input the str you want to judge:\n"); scanf("%s",str); if(Is_palindromic_str(str) != -1) { printf("It's a palidromic string!\n"); } else { printf("It's not a palidromic string!\n"); } printf("continue:1,break:0\n"); scanf("%d",&i); } return 0; }
时间: 2024-09-29 10:03:47