• 回文串(杭州电2029)


    /*Palindromes _easy version
    Problem Description
    “回文串”它是一个正读和反读同一字符串。例“level”要么“noon”等是回文序列。请编写一个程序,读取推断字符串是否“回文”。


     

    Input
    输入包括多个測试实例,输入数据的第一行是一个正整数n,表示測试实例的个数。后面紧跟着是n个字符串。

    Output
    假设一个字符串是回文串。则输出"yes",否则输出"no".

    Sample Input
    4
    level
    abcde
    noon
    haha
     

    Sample Output
    yes
    no
    yes
    no


    */

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char str[100010];
        int test,len,i,j;
        while(~scanf("%d",&test))
        {
            getchar();//注意getchar();的位置。


            while(test--)
            {
                gets(str);
                len=strlen(str);
                for(i=0,j=len-1;i<j;i++,j--)//字符串中第一个字符与最好一个字符作比較
                if(str[i]!=str[j])
                {
                    printf("no ");
                    break;
                }
                if(i>=j)
                printf("yes ");
            }
        }
        return 0;
    }      
               

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    Codeforces 67A【模拟】
    Codeforces325 D【并查集维护连通性】
    CodeForces 363D 【二分+贪心】
    Lightoj1084【DP啊DP】
    lightoj1062【几何(二分)】
    lightoj1066【BFS】
    lightoj1064 【DP求方案】
    lightoj1063【求割点】
    lightoj 1074【spfa判负环】
    CodeForces 382C【模拟】
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4666790.html
Copyright © 2020-2023  润新知