码迷,mamicode.com
首页 > 其他好文 > 详细

Palindromes UVA - 401

时间:2018-11-20 17:12:21      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:ems   signed   define   pen   for   end   scanf   ack   优化   

题意参见紫书

#include<bits/stdc++.h>
using namespace std;
#define me(s)  memset(s,0,sizeof(s))
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end
#define F first
#define S second
#define Di(x) int x;scanf("%d",&x)
#define in(x) inp(x)
#define in2(x,y) inp(x),inp(y)
#define in3(x,y,z) inp(x),inp(y),inp(z)
#define ins(x) scanf("%s",x)
#define ind(x) scanf("%lf",&x)
#define IO ios_base::sync_with_stdio(0);cin.tie(0)
#define READ freopen("C:/Users/ASUS/Desktop/in.txt","r",stdin)
#define WRITE freopen("C:/Users/ASUS/Desktop/out.txt","w",stdout)
template<class T> void inp(T &x) {//读入优化
    char c = getchar(); x = 0;
    for (; (c < 48 || c>57); c = getchar());
    for (; c > 47 && c < 58; c = getchar()) { x = (x << 1) + (x << 3) + c - 48; }
}
typedef pair <int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-15;
const char rev[] = { "A   3  HIL JM O   2TUVWXY51SE Z  8 " };
const char* msg[] = { "not a palindrome", "a regular palindrome", "a mirrored string", "a mirrored palindrome" };

char r(char ch) {
    if (isalpha(ch)) return rev[ch - A];
    return rev[ch - 0 + 25];
}

int main() {
    //READ;
    //WRITE;
    char s[30];
    while (scanf("%s", s) == 1) {
        int len = strlen(s);
        int p = 1, m = 1;
        for (int i = 0; i < (len + 1) / 2; i++) {
            if (s[i] != s[len - 1 - i]) p = 0; // 不是回文串
            if (r(s[i]) != s[len - 1 - i]) m = 0; // 不是镜像串
        }
        printf("%s -- is %s.\n\n", s, msg[m * 2 + p]);
    }
}

 

Palindromes UVA - 401

标签:ems   signed   define   pen   for   end   scanf   ack   优化   

原文地址:https://www.cnblogs.com/033000-/p/9989873.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!