----------------解决方案--------------------------------------------------------
main()
{char s[10];int i,j;
printf("Input letters:");
scanf("%s",s);
j=strlen(s);
for(i=0;i<j/2;)
{if(s[i]==s[--j])i++;
else {printf("it is not a return string");break;}
}
if(i==strlen(s)/2-1)printf("It is a return string");
getch();}
[此贴子已经被作者于2005-5-18 12:46:07编辑过]
----------------解决方案--------------------------------------------------------
//顺读和倒读都一样的字符串就叫回文字符串 方法一: #include <stdio.h> #include <string.h>
#define MAXSIZE 100
void hui_wen_string(char str[]) { char *pri; char *prj; int length; pri=str; length=strlen(str); prj=str+length-1; while(pri<prj&&(*pri==*prj)) { pri++; prj--; } if(*pri!=*prj) printf("这不是一个回文字符串!\n"); else printf("这是一个回文字符串!\n"); }
int main() { char str[MAXSIZE]; printf("请输入字符串的值:\n"); gets(str); hui_wen_string(str); return 0; } 方法二:
#include <stdio.h> #include <string.h>
#define MAXSIZE 100
int main() { char str1[MAXSIZE]; char str2[MAXSIZE]; printf("please enter the string:\n"); gets(str1); strcpy(str2,str1); strrev(str1); if(strcmp(str1,str2)==0) printf("this is a hui_wen_string!\n"); else printf("this is not a hui_wen_string!\n"); return 0; }
----------------解决方案--------------------------------------------------------
#include<iostream.h>
#include <string.h>
void main(void)
{
int flag;
char Ch[50];
cout<<"Please input String:";
cin>>Ch;
int i;
int j=strlen(Ch);
for(i=0;i<=j/2;i++)
{
if(Ch[i]==Ch[j-1])
{
flag=1;
j--;
}
else
{
flag=0;
break;
}
}
if(flag==1)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
----------------解决方案--------------------------------------------------------
原来这样
----------------解决方案--------------------------------------------------------
c++也用过来拉4楼的大哥
----------------解决方案--------------------------------------------------------