背景:1WA__for循环限制条件不正确,应该是把最中间那个词也判断一下。2WA__list表建立错误,在T之前多了一个空格。3WA——ans内单词拼写错误!!
学习:1.对于输出复杂,建表复杂的题要格外小心,什么拼写错误之类的别犯!!
2.
const char* ans[]={"is not a palindrome.","is a regular palindrome.","is a mirrored string.","is a mirrored palindrome."};
其中建立了一个字符串常量数组。
我的代码:
#include<stdio.h> #include<string.h> const char* ans[]={"is not a palindrome.","is a regular palindrome.","is a mirrored string.","is a mirrored palindrome."}; const char list[]="A 3 HIL JM O 2TUVWXY51SE Z 8 "; char make(char c); char make(char c){ if(c>='A'&&c<='Z') return list[c-'A']; else return list[c-'0'+25]; } int main(void){ char str[30]; while(scanf("%s",str)!=EOF){ int m=strlen(str); bool pal=true,mir=true; for(int i=0;i<(m+1)/2;i++){ if(str[i]!=str[m-i-1]) pal=false; if(make(str[i])!=str[m-i-1]) mir=false; } printf("%s -- %s\n\n",str,ans[pal+mir*2]); } }
时间: 2024-10-10 08:30:41