lll______g 2018-11-02 01:38 采纳率: 0%
浏览 4754

回文串是从左到右或者从右到左读起来都一样的字符串,试编程判别一个字符串是否为回文串

#include
int main()
{
char s[270];
gets(s);
int i,j,y=0;
if(strlen(s)%2!=0)
{
for(i=0,j=strlen(s);i<(strlen(s)+1)/2;i++,j--)
{
if('s[i]'=='s[j]')//为什么这里判断不了两个字符相等
y++;
printf("*");
}
printf("%d",y);//输出y 一直为0
}
else
{
printf("N");
}
}

  • 写回答

2条回答 默认 最新

  • threenewbee 2018-11-02 01:53
    关注
    #include "stdio.h"
    #include "string.h"
    
    int main()
    {
    char s[270];
    gets(s);
    int i,j,y=0;
    if(strlen(s)%2!=0)
    {
    for(i=0,j=strlen(s)-1;i<(strlen(s)+1)/2;i++,j--)
    {
    if(s[i]==s[j])//为什么这里判断不了两个字符相等
    y++;
    printf("*");
    }
    printf("%d",y);//输出y 一直为0
    }
    else
    {
    printf("N");
    }
    }
    

    图片说明

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型