hdu2029 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()
{
    int n,k,i;
    char a[100];
    scanf("%d",&n);
    getchar();
    while(n--)
    {
        gets(a);
        k=0;
        for(i=0;i<=(strlen(a)+1)/2;i++)
        {
           if(a[i]!=a[strlen(a)-1-i])
           {
            k=1;break;
           }
        }
        if(k==1)
        printf("no\n");
        else
        printf("yes\n");
    }
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章