zoukankan      html  css  js  c++  java
  • UVa 401 Palindromes

    题目大意:Palindrome的定义是,一个字符串从左向右和从右向左读是一样的;Mirrored string的定义是,一个字符串左右对称;Mirrored palindrome就是既palindrome又mirrored的字符串。对称的关系表题目中已给出。

    #include<stdio.h>
    #include<string.h>
    const char one[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
    const char two[]="A   3 HIL JM O   2TUVWXY51SE Z 8 ";
    const long len=35;
    bool Palindrome(const char *s)
    {
        long begin=0,end=strlen(s)-1;
        while(begin<=end)
        {
           if(s[begin]==s[end])
           {
              begin++;
              end--;
           }
           else
             return false;
        }
        return true;
    }
    long pos(char ch)
    {
        for(long i=0;i<len;i++)
          if(one[i]==ch)
            return i;
        return len;
    }
    bool Mirror(const char *s)
    {
        long begin=0,end=strlen(s)-1;
        while(begin<=end)
        {
           long tmp=pos(s[begin]);
           if(s[end]==two[tmp])
           {
              begin++;
              end--;
           }
           else
             return false;
        }
        return true;
    }
    int main()
    {
        char str[1000];
        while(gets(str)!=0)
        {
           bool a=false,b=false;
           a=Palindrome(str);
           b=Mirror(str);
           if(a&&b)
             printf("%s -- is a mirrored palindrome.\n",str);
           else if(a)
             printf("%s -- is a regular palindrome.\n",str);
           else if(b)
             printf("%s -- is a mirrored string.\n",str);
           else
             printf("%s -- is not a palindrome.\n",str);
           putchar('\n');
        }
    return 0;
    }
    

      


  • 相关阅读:
    webapi支持session
    webapi返回数据同时支持xml与json
    webapi权限控制
    Asp.net 将js文件打包进dll 方法
    All Media to FLV asp.net在线视频自动转换并截图调试成功!
    未能从程序集“System.ServiceModel
    [javascript]浮动广告
    [python]multi thread tcp connect port scanner
    [vc]让你Y的用YY
    [python]扫描网站后台脚本
  • 原文地址:https://www.cnblogs.com/rollenholt/p/2410753.html
Copyright © 2011-2022 走看看