uva401 镜像字符串

题意:输入一串字符串,判断是回文字符,还是镜像字符,还是镜像字符,还是两者都不是


首先把所有镜像字符都预处理出来,然后保存到数组里,最后暴力判断即可

#include 
#include 
#include 
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define MAXN 50

using namespace std;

char miroralpha[] = "A   3  HIL JM O   2TUVWXY5";
char mirordigit[] = "1SE Z  8 ";
char ans[4][100] = {" -- is not a palindrome." , " -- is a regular palindrome." , " -- is a mirrored string." , " -- is a mirrored palindrome."};

char miror(char c)
{
    if(c >= 'A' && c <= 'Z')
        return miroralpha[c - 'A'];
    else
        return mirordigit[c - '1'];
}

int ask(char s[])
{
    int p = 1, m = 1;
    int n = strlen(s)-1;
	rep (start, 0, n - 1)
    {
        if(s[start] != s[n])
            p = 0;
        if(miror(s[start]) != s[n])
            m = 0;
		n--;
    }

    return m * 2 + p;
}

int main()
{
    char s[MAXN];

    while(scanf("%s", s) == 1)
        printf("%s%s\n\n", s, ans[ ask(s)]);

    return 0;
}


你可能感兴趣的:(字符串,uva)