#include
#defineis_palindrome1
#defineis_not_palindrome0
#definestr_yes"yes"
#definestr_no"no"
#definemax_size80
intispalindrome(charstr[]);
intmain()
{
charstr[max_size+1];
printf("請輸入一個字串:\n");
/*獲取使用者輸入的字串*/
gets(str);
/*判斷是否迴文並輸出相應資訊*/
if(ispalindrome(str)==is_palindrome)
printf(str_yes);
}
else
printf(str_no);
return0;
/*
判斷給定字串是否為迴文
str——待判斷的字串
如果str是迴文,返回1;否則返回0
*/
intispalindrome(charstr[])
intlength=0;/*字串長度*/
inti=0;
如果字串長度為0或負值,則認為它不是迴文;
否則,將首尾對應的字元進行比較:
——如果有任意一組對應的字元不相等,則認為它不是迴文;
——否則認為是迴文.
if((length=strlen(str))
returnis_not_palindrome;
for(i=0;i
#include
#include
#defineis_palindrome1
#defineis_not_palindrome0
#definestr_yes"yes"
#definestr_no"no"
#definemax_size80
intispalindrome(charstr[]);
intmain()
{
charstr[max_size+1];
printf("請輸入一個字串:\n");
/*獲取使用者輸入的字串*/
gets(str);
/*判斷是否迴文並輸出相應資訊*/
if(ispalindrome(str)==is_palindrome)
{
printf(str_yes);
}
else
{
printf(str_no);
}
return0;
}
/*
判斷給定字串是否為迴文
str——待判斷的字串
如果str是迴文,返回1;否則返回0
*/
intispalindrome(charstr[])
{
intlength=0;/*字串長度*/
inti=0;
/*
如果字串長度為0或負值,則認為它不是迴文;
否則,將首尾對應的字元進行比較:
——如果有任意一組對應的字元不相等,則認為它不是迴文;
——否則認為是迴文.
*/
if((length=strlen(str))
{
returnis_not_palindrome;
}
else
{
for(i=0;i