UVA401 回文词(字符串二维数组,ctype.h全家桶)

  1. ctype.h:包括:isalpha()  ; idigit()  ;  isprint()  ;用来判断字符的属性。tolower()  ;   toupper()  ;改变字母的大小写。

  2. mg[ ]={"     " , "######",  "%%%%%%%%%"}   这是字符串二维数组。mg【】的每一个元素都是一个字符串。

  3. 书上最后输出的时候用了数学公式。鬼畜,怎么想到的!!!

  4. 常量数组:怎么转换的(如何建立的映射关系),看蒙了。

#include<iostream>
#include<algorithm>
#include<stack>
#include<set>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<ctype.h>
using namespace std;
char *s="A   3  HIL JM O   2TUVWXY51S  Z  8";
char *mg[]={" -- is not a palindrome."," -- is a regular palindrome."," -- is a mirrored string."," -- is a mirrored palindrome." };
char str[100];
char r(char ch)
{
    if(isalpha(ch)) return s[ch-'A'];
    else            return s[ch-'0'+25];
}
int main()
{
    while(gets(str)!=NULL)
    {
        int p=1,m=1;
        for(int i=0;i<(strlen(str)+1)/2;i++)
        {
            if(str[i]!=str[strlen(str)-1-i]) p=0;
            if(str[i]!=r(str[strlen(str)-1-i])) m=0;//这是怎样建立的映射?????我怎么没看明白??脑子里想不出来呀!!!)
        }
        if(p==0&&m==1) cout<<str<<mg[2]<<endl;
        else if(p==1&&m==0) cout<<str<<mg[1]<<endl;
        else if(p==1&&m==1) cout<<str<<mg[3]<<endl;
        else                cout<<str<<mg[0]<<endl;
        p=1;m=1;
        cout<<endl;
    }
    return 0;
}
发布了77 篇原创文章 · 获赞 11 · 访问量 5008

猜你喜欢

转载自blog.csdn.net/qq_43346054/article/details/100803219