你把这说清楚了我再补充回答你~
我写了个参考代码给你参考, 首先是输入你要谈差判断的字符串的个数, 然后再依次输入所有的字符串, 最后判断输入的所有字符串是否是"回文"! 因为不理解你那句话, 所以暂时没做什么空和什么"#"处理.
详细c代码:
#include <stdio.h>
#include <string.h>
#define STR_LEN 128
#define STR_NUM 64
int main()
{
int i = 0, j = 0, n = 0
int len = 0
char *start = NULL
char *end = NULL
char str[STR_NUM][STR_LEN] = {0}
printf("Please input the number of string: \n")
scanf("%d", &n)
printf("Please input all the string: \n")
for (i = 0i <ni++)
{
scanf("%s", str[i])
}
for (j = 0j <nj++)
{
start = str[j]
len = strlen(str[j])
end = str[j] + len - 1
while (start - end <= 0)
{
if (*start++ != *end--)
{
break
}
}
if (start >end)
{
printf("yes\n")
}
else
{
printf("no\n")
}
}
return 0
}
例子,运行后:
Please input the number of string:
4
Please input all the string:
aba
112ds
madam
xyzyx
yes
no
yes
yes
Press any key to continue
补充回答:
大森兄概明白你的意思,我会此侍袭把例子贴上, 若不符合你的要求我再帮修改!
详细代码如下:
#include <stdio.h>
#include <string.h>
#define STR_LEN 128
#define STR_NUM 64
int main()
{
int i = 0
int len = 0
int str_count = 0
char *start = NULL
char *end = NULL
char str[STR_NUM][STR_LEN] = {0}
printf("Please input all the string: \n")
while (1)
{
scanf("%s", str[str_count])
if (str[str_count][0] == '#')
{
break
}
else
{
str_count++
continue
}
}
for (i = 0i <str_counti++)
{
start = str[i]
len = strlen(str[i])
end = str[i] + len - 1
while (start - end <= 0)
{
if (*start++ != *end--)
{
break
}
}
if (start >end)
{
printf("yes\n")
}
else
{
printf("no\n")
}
}
return 0
}
运行实例1:
Please input all the string:
xyzyx
adghf
#
yes
no
Press any key to continue
运行实例2:
Please input all the string:
1232ss
sakljfkla
333dafs
aba
ee3
xyzyx
dfj222
madam
111$111
slsl33
#
no
no
no
yes
no
yes
no
yes
yes
no
Press any key to continue
有分多多给啊,我给你费了不少时间呢。程序完全没有问题,你所说的功能都笑肢给你做到了哦!槐升袭#include<stdio.h>
#include<string.h>
int main()
{
char buf[1000]={0}
printf("Please input :\n")
int i,j,k=0
for(i = 0i<1000i++){
buf[i] = getchar()
if(buf[i] == '\n' )
break
}
printf("%s\n",buf)
for(i = 0 i<1000 i++ ){
j = buf[i]
if( ( j>=48 &&j<=57 )|| (j>=65 &&j<=90 ))
buf[k++] = j
else if((j>=97 &&j<=122) )
buf[k++] = j-32
else if(j == '\n' ){
buf[k] = '\0'
break
}
}
printf("%s\n",buf)
j = strlen(buf)
for(i = 0 i <strlen(buf)/2 i++,j--){
if( buf[i] != buf[j-1] )
break
}
if(i != strlen(buf)/2 )
printf("No i=%d\n",i)
else
printf("Yes\铅兄n")
}
#include <stdio.h>int palindrome(char *string)
void main()
{int i
char str[100],*string=str
gets(string)
i=palindrome(string)
printf("i=%d\n",i)
getch()
}
int palindrome(char *string)
{int n=0,i,flag=1
char *p=string
while(*p!='凯拍\物猛0'盯蚂羡)
{n++p++}
for(i=0i<=n/2i++)
{if(*(string+i)==*(string+n-i-1))
else return 0
}
return 1}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)