題意:

給一個字串,如果可以拆成兩個回文輸出alindrome,只能有一個回文輸出palindrome,如果其他狀況就輸出simple

 

解法:

暴力拆兩邊去檢查兩邊是不是回文

 

程式碼

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

char str[654321];
int main(){
    int t;
    int i,j,k;
    int l;
    scanf("%d",&t);
    gets(str);
    while(t--){
        gets(str);
        l = strlen(str);
        for(k=l-1;k>=0;--k){
            for(i=0,j=k-1;i<j && str[i]==str[j];++i,--j);
            if(i<j)continue;
            for(i=k,j=l-1;i<j && str[i]==str[j];++i,--j);
            if(i>=j)break;
        }
        if(k==0)puts("palindrome");
        else if(k>0)puts("alindrome");
        else puts("simple");
    }
    return 0;
}

arrow
arrow
    全站熱搜

    alan790712 發表在 痞客邦 留言(0) 人氣()