鱼C论坛

 找回密码
 立即注册
查看: 2038|回复: 7

[已解决]删除前后空格 并判断是否为回文

[复制链接]
发表于 2017-12-12 11:28:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
我不知道哪里错了  输不出来

#include<stdio.h>
#include<string.h>
int main ()
{
        char s[80],ch,*p,*q;
        int n;
        gets(s);
        p=s;
    while(*p==' ')
    *p=*p++;
    n=strlen(s);
    q+=n-1;
    while(*q==' ')
    *q=*q--;
    while(p<q&&*p==*q)
    {
            p++;
            q--;
        }
    if(p<q)
    printf("no\n");
    else
    printf("yes");
}
最佳答案
2017-12-12 12:22:09
倒影Gaara 发表于 2017-12-12 11:44
题目是到填空题
  #include
#include

那就改成 q = s + n - 1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-12-12 11:33:40 | 显示全部楼层
q没有初始化,怎么可以执行
q+=n-1;

另外gets函数并不靠谱,建议使用fgets函数
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-12-12 11:36:19 | 显示全部楼层
BngThea 发表于 2017-12-12 11:33
q没有初始化,怎么可以执行
q+=n-1;

那应该怎么初始化  q  ?
我们刚接触指针
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-12-12 11:39:32 | 显示全部楼层
倒影Gaara 发表于 2017-12-12 11:36
那应该怎么初始化  q  ?
我们刚接触指针

根据你的意思,你应该将它也指向s
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-12-12 11:44:34 | 显示全部楼层
BngThea 发表于 2017-12-12 11:39
根据你的意思,你应该将它也指向s

题目是到填空题
  #include<stdio.h>
#include<string.h>
int main ()
{
&nbsp; &nbsp; &nbsp; &nbsp; char s[80],ch,*p,*q;
&nbsp; &nbsp; &nbsp; &nbsp; int n;
&nbsp; &nbsp; &nbsp; &nbsp; gets(s);
&nbsp; &nbsp; &nbsp; &nbsp; p=s;
&nbsp; &nbsp; while(*p==' ')
&nbsp; &nbsp; *p=——;
&nbsp; &nbsp; n=strlen(s);
&nbsp; &nbsp; q=——;
&nbsp; &nbsp; while(*q==' ')
&nbsp; &nbsp; ——;
&nbsp; &nbsp; while(——&&*p==*q)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p++;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ——;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; if(p<q)
&nbsp; &nbsp; printf("no\n");
&nbsp; &nbsp; else
&nbsp; &nbsp; printf("yes");
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-12-12 11:50:33 | 显示全部楼层
#include<stdio.h>
#include<string.h>
int main ()
{
&nbsp; &nbsp; &nbsp; &nbsp; char s[80],ch,*p,*q;
&nbsp; &nbsp; &nbsp; &nbsp; int n;
&nbsp; &nbsp; &nbsp; &nbsp; gets(s);
&nbsp; &nbsp; &nbsp; &nbsp; p=s;
&nbsp; &nbsp; while(*p==' ')
&nbsp; &nbsp; ——;
&nbsp; &nbsp; n=strlen(s);
&nbsp; &nbsp; q=——;
&nbsp; &nbsp; while(*q==' ')
&nbsp; &nbsp; ——;
&nbsp; &nbsp; while(——&&*p==*q)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p++;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ——;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; if(p<q)
&nbsp; &nbsp; printf("no\n");
&nbsp; &nbsp; else
&nbsp; &nbsp; printf("yes");
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-12-12 12:22:09 | 显示全部楼层    本楼为最佳答案   
倒影Gaara 发表于 2017-12-12 11:44
题目是到填空题
  #include
#include

那就改成 q = s + n - 1
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-12-12 12:26:57 | 显示全部楼层
BngThea 发表于 2017-12-12 12:22
那就改成 q = s + n - 1

还是输不出来  请问我删除前后空格那里是不是对的啊 ?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 12:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表