欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

UVA401 回文词 Palindromes

程序员文章站 2022-03-13 17:32:00
...

知识储备:
映射串:构建映射表
UVA401 回文词 Palindromes

 上述的映射表

string strMap="A    3   HIL JM O   2TUVWXY51SE Z  8 "; 

char mmap(char ch){
	if(ch>='A'&&ch<='Z'){
		return strMap[ch-'A'];//字母映射 
	}else{
		return strMap[ch-'0'+25];//字符映射 
	}
}
#include <bits/stdc++.h>
using namespace std;
string strMap="A    3   HIL JM O   2TUVWXY51SE Z  8 "; 

char mmap(char ch){
	if(ch>='A'&&ch<='Z'){
		return strMap[ch-'A'];//字母映射 
	}else{
		return strMap[ch-'0'+25];//字符映射 
	}
}

int main(){
	string s;
	while(cin>>s){
		int len=s.length();
		bool flag1=true;//回文串
		bool flag2=true;//为镜像串 
		for(int i=0;i<(len+1)/2;i++){
			if(s[i]!=s[len-1-i]){
				flag1=false;
			}
			if(mmap(s[i])!=s[len-1-i]){
				flag2=false;
			}		
		}
		if(flag1==true&&flag2==true){
			cout<<s<<" -- is a mirrored palindrome."<<endl<<endl;
		}
		if(flag1==true&&flag2==false){
			cout<<s<<" -- is a regular palindrome."<<endl<<endl;
		}
		if(flag1==false&&flag2==false){
			cout<<s<<" -- is not a palindrome."<<endl<<endl;
		}
		if(flag1==false&&flag2==true){
			cout<<s<<" -- is a mirrored string."<<endl<<endl;	
		}		
	}

	return 0;
}