G - Mirror, Mirror on the Wall (if判断)

题意链接:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    char s[100];
    while(~scanf("%s",s))
    {
        if(s[0]=='#')//就是这里一开始直接s=="#"就不会出现直接返回,但如果是str=="#"就能得出想要的结果
            return 0;
        int len=strlen(s);
        int flag=1;
        for(int i=0;i<len;i++)
        {
            if(s[i] == 'b')
                s[i] = 'd';
            else if(s[i] == 'd')
                s[i] = 'b';
            else if(s[i] == 'p')
                s[i] = 'q';
            else if(s[i] == 'q')
                s[i] = 'p';
            else if(s[i]!='i'&&s[i]!='o'&&s[i]!='v'&&s[i]!='w'&&s[i]!='x')
                flag=0;

        }
        if(flag==1)
        {
             for(int j=len-1;j>=0;j--)
            printf("%c",s[j]);
        printf("\n");
        }
        else
        {
        printf("INVALID\n");
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42232118/article/details/81583668