国王的魔镜 n 264

递归函数的简单应用可怜可怜

#include<stdio.h>
#include<string.h>

char a[105];

int Match(num)        //判断匹配
{
    if((num%2)==1)
         return num;
    else
    {
         int i;
         for(i=0;i<(num/2);i++)
         {
             if(a[i] != a[num-1-i])
                 break;
         }
         if(i < (num/2))
             return num;
         else 
             return (Match(num/2));
    }
} 

int main()
{
    int length, n;
    scanf("%d", &n);
    while(n--)
    {
        scanf("%s", a);
        length = strlen(a);
        int minleng = Match(length);
        printf("%d\n", minleng);
    }
    return 0;
}


 

posted on 2011-12-02 01:23  java课程设计例子  阅读(218)  评论(0编辑  收藏  举报