Analyzing water --- mirror title string string and flashback

Topic link: https: //vjudge.net/problem/UVA-401

Meaning of the questions: to determine whether the image and reverse the string string

Solution: to determine whether each of: determining whether the same reverse sequence flashback

                                    Tandem mirror determines whether two strings are equal

Note: 1. Note that the output format, there is a space after each output  

           2. Analyzing two image string that satisfies conditions: First, whether the character string, the two are equal is indispensable

          3.C ++ character length used .length () to seek, strlen是计算char */char[]的,string非要用,需要用 c_str()转换成char * cout << strlen(s.c_str()),类似的也包括输出字符串%s

ac Code

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main()
{
    char ch[]="AEHIJLMOSTUVWXYZ12358";
    char ch2[]="A3HILJMO2TUVWXY51SEZ8";
    string s;
    while(getline(cin,s))
    {
        int j,f1=1,f2=1;
        int len=s.length();
        for(int i=0;i<=len/2;i++)
            if(s[i]!=s[len-i-1])
        {
            f1=0;
            break;
        }
        for(int i=0;i<=len/2;i++)
        {
            for(j=0;ch[j]!=0;j++)
                if(ch[j]==s[i]) break;
            if(!ch[j]||ch2[j]!=s[len-i-1]) f2=0;
        }
        cout<<s;
        if(f1&&f2) printf(" -- is a mirrored palindrome.\n",s);
        else if(!f1&&f2) printf(" -- is a mirrored string.\n",s);
        else if(f1&&!f2) printf(" -- is a regular palindrome.\n",s);
        else printf(" -- is not a palindrome.\n",s);
        cout<<endl;
    }
    return 0;
}

    

Guess you like

Origin www.cnblogs.com/Joe2019/p/12654893.html