Palindromes (Palindromes, UVa401) (C++)

Enter a string to determine whether it is a palindrome and a mirrored string. The number 0 is not included in the input string. The so-called palindrome string is the same as the original string after inversion, such as abba and madam.
#include<iostream>
#include<cstring>
using namespace std;
char qq[]="A   3  HIL JM O   2TUVWXY51SE Z  8 ";
const char *end[4]={
    
    "这不是回文字符串!","这是镜像字符串!","这是回文字符串!","这是回文镜像字符串!"}; 
char judge(char a)
{
    
    
	if(isalpha(a))
	{
    
    
		return qq[a-'A'];
	}
	else
		return qq[a-'0'+25];
}
int main()
{
    
    
	int q,m;
	char a[200];
	while(cin>>a)
	{
    
    
		q=1;//判断是不是回文数 
		m=1;//判断是不是镜像数 
		int len=strlen(a);
		for(int i=0;i<len/2;i++)
		{
    
    
			if(judge(a[i])!=a[len-i-1])
			m=0;
			if(a[i]!=a[len-i-1])
			q=0;
			if(m==0&&q==0)
			break;
		}
		cout<<end[m+q*2]<<endl;//这个形式挺新颖的,相比较与三个if语句这一行代码就很简洁 
		
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/Huo6666/article/details/107610277