0
我想問題401 - 迴文弗吉尼亞網上法官,但我一直得到一個失敗...你可以找到問題hereUVA-401:迴文,輸出超限
這裏是我的代碼:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char reverse_t[36] = {' ','1','S','E',' ','Z',' ',' ','8',' ',
'A',' ',' ',' ','3',' ',' ',
'H','I','L',' ','J','M', ' ',
'O', ' ', ' ', ' ','2','T',
'U','V','W','X','Y','5'};
int is_mirror(char a,char b){
if(a>='1' && a<='9'){
if(reverse_t[a-'0'] == b) return 1;}
else if(a>='A' && a<='Z')
{if(reverse_t[a-'A'+10] == b) return 1;}
return 0;
}
int main(int argc, char **argv) {
char line[21];
size_t len;
int is_palinedromes, is_mirrored;
while(scanf("%20s",line)){
is_palinedromes = 1;
is_mirrored = 1;
int i;
len = strlen(line);
for(i = 0;i<len/2;i++){
if(line[i] != line[len-1-i])
is_palinedromes =0;
if(!is_mirror(line[i],line[len-1-i]))
is_mirrored = 0;
}
if((len%2==1)&&(is_mirrored))
if(!is_mirror(line[len/2],line[len/2]))
is_mirrored = 0;
if(is_palinedromes && is_mirrored)
printf("%s -- is a mirrored palindrome.\n",line);
else if(is_mirrored &&(!is_palinedromes))
printf("%s -- is a mirrored string.\n",line);
else if((!is_mirrored)&&is_palinedromes)
printf("%s -- is a regular palindrome.\n",line);
else
printf("%s -- is not a palindrome.\n",line);
printf("\n");
}
return 0;
}
我的字母鏡存儲在陣列reverse_t,我可以由函數is_mirror檢查的信鏡。
和判決是「輸出超限」
我會明白任何建議。謝謝。