• UVA401(回文子串和镜像串)


    可以先设一个常量镜像串,直接返回比较

    #include <iostream>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <cctype>
    using namespace std;
    
    #define mem(a,b) memset(a,b,sizeof(a))
    #define pf printf
    #define sf scanf
    #define spf sprintf
    #define debug printf("!
    ")
    #define INF 10000
    #define MAXN 5010
    #define MAX(a,b) a>b?a:b
    #define blank pf("
    ")
    #define LL long long
    
    const char* rev = "A   3  HIL JM O   2TUVWXY51SE Z  8 ";
    const char* msg[]={"is not a palindrome.","is a regular palindrome.","is a mirrored string.","is a mirrored palindrome."};
    
    char str[MAXN];
    
    char change(char ch)
    {
         if(isalpha(ch)) return rev[ch-'A'];
         return rev[ch-'0'+25];
    }
    
    int main()
    {
         while(~sf("%s",str))
         {
              int p=1,m=1,i;
              int len = strlen(str);
              for(i=0;i<(len+1)/2;i++)
              {
                   if(str[i]!=str[len-i-1]) p=0;
                   if(change(str[i])!=str[len-i-1]) m=0;
              }
              pf("p:%d m:%d
    ",p,m);
              pf("%s -- is %s
    ",str,msg[p+m*2]);
         }
    }
    /*
    NOTAPALINDROME
    ISAPALINILAPASI
    2A3MEAS
    ATOYOTA
    */
  • 相关阅读:
    【转】进程与线程的一个简单解释
    折半查找
    BOJ 89 统计时间间隔
    BOJ 88 最值问题
    BOJ 87 日期
    QT杂记(网上资料整理而成)
    我的博客园
    【制作镜像】virsh
    【培训】MySQL
    ERROR 1045 (28000): Access denied for user 'root'@'localhost'
  • 原文地址:https://www.cnblogs.com/qlky/p/5171009.html
Copyright © 2020-2023  润新知