编程介的小学生 2019-08-10 13:08 采纳率: 20.5%
浏览 1214

判断是不是回文字符串,用的C语言

Problem Description
Write a program to determine whether a word is a palindrome. A palindrome is a sequence of characters that is identical to the string when the characters are placed in reverse order. For example, the following strings are palindromes: “ABCCBA”, “A”, and “AMA”. The following strings are not palindromes: “HELLO”, “ABAB” and “PPA”.

Input
The input file will consist of up to 100 lines, where each line contains at least 1 and at most 52 characters. Your program should stop processing the input when the input string equals “STOP”. You may assume that input file consists of exclusively uppercase letters; no lowercase letters, punctuation marks, digits, or whitespace will be included within each word.

Output
A single line of output should be generated for each string. The line should include “#”, followed by the problem number, followed by a colon and a space, followed by the string “YES” or “NO”.

Sample Input
ABCCBA
A
HELLO
ABAB
AMA
ABAB
PPA
STOP

Sample Output
#1: YES
#2: YES
#3: NO
#4: NO
#5: YES
#6: NO
#7: NO

  • 写回答

1条回答

  • aFakeProgramer 2019-08-10 13:38
    关注

    bool is_palindrome(char* a,int n)
    {
    bool ret=false;
    int i=0,j=n-1;
    for(;i<=j;i++,j--)
    {
    if(a[i]==a[j])
    {
    continue;
    }else
    {
    printf("NO\n");
    return ret;
    }

    }
    if(a[i]==a[j])
    {
        ret = true;
        printf("YES\n");       
    }
    
    return ret;
    

    }

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料