zoukankan      html  css  js  c++  java
  • 武汉科技大学ACM :1004: 零起点学算法74——Palindromes _easy version

    Problem Description

    “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。

    Input

    输入包含多个测试实例,输入数据的第一行是一个正整数n,表示测试实例的个数,后面紧跟着是n个字符串。每个字符串长度不超过150。

    Output

    如果一个字符串是回文串,则输出"yes",否则输出"no".

    Sample Input

    4

    level

    abcde

    noon

    haha

    Sample Output

    yes

    no

    yes

    no

     1 #include<stdio.h>
     2 
     3 #include<string.h>
     4 
     5 int fun(char a[])
     6 
     7 {       
     8 
     9          int i,k,r=1;        
    10 
    11          k=strlen(a)-1;  
    12 
    13          for(i=0;i<=k;k--,i++)          
    14 
    15          {                
    16 
    17                    if(a[i]!=a[k])                        
    18 
    19                    {                          
    20 
    21                             r=0;
    22 
    23                             break;
    24 
    25                    }
    26 
    27          }
    28 
    29          return r;
    30 
    31 }
    32 
    33 int main()
    34 
    35 {
    36 
    37          char a[20];
    38 
    39          int i,n;
    40 
    41          scanf("%d",&n);
    42 
    43          for(i=0;i<n;i++)
    44 
    45          {
    46 
    47                    scanf("%s",&a);
    48 
    49                    if(fun(a)==0)
    50 
    51                             printf("no
    ");
    52 
    53                    else
    54 
    55                             printf("yes
    ");
    56 
    57          }
    58 
    59          return 0;
    60 
    61 }

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char str[20];
        int n,i,j;
        scanf("%d",&n);
        while(n>0)
        {
            scanf("%s",str);
            i=0;
            j=strlen(str)-1;
            while(i<=j)
            {
                if(str[i]!=str[j])
                    break;
                i++;
                j--;
            }
            if(i>j)
                printf("yes
    ");
            else
                printf("no
    ");
            n--;
        }
        return 0;
    }
  • 相关阅读:
    robot framework 初始化清除
    python获取命令行参数
    行业基金
    Ubuntu关闭开机自启项
    ubuntu18.04安装adb
    JavaScript
    centos关闭开机自启项
    CSDN值得学习的专栏
    ubuntu和centos操作命令对比
    linux解压文件命令
  • 原文地址:https://www.cnblogs.com/liuwt365/p/4154137.html
Copyright © 2011-2022 走看看