雖然一直在看小白書,可是從來沒刷過uva上的題目(不是不刷,是找不到怎麼進去,對自己的英語確實很無力,鄙視我吧)。然後今天意外的進去了,以後就要好好的做做這上邊的題目,感覺很好的,這是我在uva上的第一道題目,是個簡單題(wo hen shui),可是還是沒有一遍AK。。。
鏈接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342
題意:剛開始沒看懂那個mirrored string 到底是怎麼搞的,然後看了下邊的表格就明白了,就相當於鏡像原理。至於迴文串不用解釋。。。只是做的時候直接將最後的每個輸出後有空行自動給忽略了,然後WA了4次,感覺代碼確實沒問題,看了下別人的,發現人家都換兩次行,改了之後發現ac了,唯一不明的是uva的平臺爲什麼輸出錯誤是wa,讓我一直在那調試一個輸出格式有錯的代碼[無語]。
#include<stdio.h>
#include<string.h>
char str1[]={'A',' ',' ',' ','3',' ',' ','H','I','L',' ','J','M',' ','O',' ',' ',' ','2','T','U','V','W','X','Y','5'};
char str2[]={'O','1','S','E',' ','Z',' ',' ','8',' '};
int palindrome(char str[])//判斷是否是迴文串
{
int b=strlen(str);
int i,j;
for( i=0,j=b-1;i<=j;i++,j--)
if(str[i]!=str[j])
return 0;
return 1;
}
int mirrored(char str[])//判斷是否是鏡像
{
int i,j;
int b=strlen(str);
for(i=0,j=b-1;i<=j;i++,j--)
{
if(str[i]>='A'&&str[i]<='Z')
{
if(str1[str[i]-65]!=str[j])
return 0;
}
else if(str[i]>='0'&&str[i]<='9')
{
if(str2[str[i]-'0']!=str[j])
return 0;
}
}
return 1;
}
int main()
{
char str[25];
while(scanf("%s",str)!=EOF)
{
int n,m;
printf("%s -- ",str);
n=palindrome(str);
m=mirrored(str);
if(n&&m)
printf("is a mirrored palindrome.\n\n");
else if(n==1&&m==0)
printf("is a regular palindrome.\n\n");
else if(n==0&&m==1)
printf("is a mirrored string.\n\n");
else
printf("is not a palindrome.\n\n");
}
return 0;
}