2014-04-09 21 views
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检查的信镜。

和判决是“输出超限

我会明白任何建议。谢谢。

回答

2

好像有输入没有结束,所以我只是代码

while(scanf("%20s",line)) 

改变

while(scanf("%20s",line)!=EOF) 

,然后我得到了AC :)。