HDU1318 POJ1590 UVA401 ZOJ1325 Palindromes

问题链接:HDU1318 POJ1590 UVA401 ZOJ1325 Palindromes。基础练习题,用C语言编写程序。

程序中,使用两个函数封装功能,使得程序更加简洁易懂。

判定回文时,使用两个数组下标相向移动,是一种常见的套路。

AC的C语言程序如下:

/* HDU1318 POJ1590 UVA401 ZOJ1325 Palindromes */

#include <stdio.h>
#include <ctype.h>
#include <string.h>

#define MAXN 30

char miroralpha[] = "A   3  HIL JM O   2TUVWXY5";
char mirordigit[] = "1SE Z  8 ";
char *msg[] = {" -- is not a palindrome."
               , " -- is a regular palindrome."
               , " -- is a mirrored string."
               , " -- is a mirrored palindrome."};

/* 字母镜像 */
char miror(char c)
{
    if(isalpha(c))
        return miroralpha[c - 'A'];
    else
        return mirordigit[c - '1'];
}

/* 计算字符串类型 */
int gettype(char s[])
{
    int start, end, p, m;

    p = 1;  /* 回文标志 */
    m = 1;  /* 镜像标志 */

    start = 0;
    end = strlen(s)-1;
    while(start <= end) {
        if(s[start] != s[end])
            p = 0;
        if(miror(s[start]) != s[end])
            m = 0;
        start++;
        end--;
    }

    return m * 2 + p;
}

int main(void)
{
    char s[MAXN];

    while(scanf("%s", s) != EOF)
        printf("%s%s\n\n", s, msg[gettype(s)]);

    return 0;
}
时间: 2024-10-18 07:56:30

HDU1318 POJ1590 UVA401 ZOJ1325 Palindromes的相关文章

【UVA401】Palindromes

Palindromes Time Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu SubmitStatusPracticeUVA 401 Appoint description: Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, th

回文词 (Palindromes,Uva401)

例题 3-3 回文词 (Palindromes,Uva401) 输入一个字符中,判断它是否为回文串以及镜像串.输入字符串保证不含数字0.所谓回文串,就是反转以后和原串相同,如abba和madam.所有镜像串,就是左右镜像之后和原串相同,如2S和3AIAE.注意,并不是每个字符在镜像之后都能得到一个合法字符.在本题中,每个字符的镜像如图3-3所示(空白项表示该字符镜像后不能得到一个合法字符). 输入的每行包含一个字符串(保证只有上述字符.不含空白字符),判断它是否为回文串和镜像串(共4种组合).每

UVa401 Palindromes

 Palindromes  A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string i

【紫书】例题3-3 回文词(Palindromes, UVa401)

[题目描述] 输入一个字符串,判断它是否为回文串以及镜像串.输入字符串保证不含数字0.所谓回文串,就是反转以后和原串相同,如abba和madam.所有镜像串,就是左右镜像之后和原串相同,如2S和3AIAE.注意,并不是每个字符在镜像之后都能得到一个合法字符.在本题中,每个字符的镜像如图所示(空白项表示该字符镜像后不能得到一个合法字符). 输入的每行包含一个字符串(保证只有上述字符.不含空白字符),判断它是否为回文串和镜像串(共4种组合).每组数据之后输出一个空行. [样例输入] NOTAPALI

回文词(Palindromes, UVa401)

输入一个字符串,判断它是否为回文串以及镜像串.输入字符串保证不含数字0. 所谓 回文串,就是反转以后和原串相同,如abba和madam. 所谓镜像串,就是左右镜像之后和原串相同,如2S和3AIAE. 注意,并不是每个字符在镜像之后都能得到一个合法字符.在本题中,每个字符的镜像如图所示(空白项表示该字符镜像后不能得到一个合法字符). 输入的每行包含一个字符串(保证只有上述字符.不含空白字符),判断它是否为回文 串和镜像串(共4种组合).每组数据之后输出一个空行. 样例输入: NOTAPALINDR

UVa401 回文词

Palindromes A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string is

[UVa] Palindromes(401)

UVA - 401 Palindromes Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDED

uva 11584 Partitioning by Palindromes 线性dp

// uva 11584 Partitioning by Palindromes 线性dp // // 题目意思是将一个字符串划分成尽量少的回文串 // // f[i]表示前i个字符能化成最少的回文串的数目 // // f[i] = min(f[i],f[j-1] + 1(j到i是回文串)) // // 这道题还是挺简单的,继续练 #include <algorithm> #include <bitset> #include <cassert> #include <

Codeforces Round #316 (Div. 2)E. Pig and Palindromes DP

E. Pig and Palindromes Peppa the Pig was walking and walked into the forest. What a strange coincidence! The forest has the shape of a rectangle, consisting of n rows and m columns. We enumerate the rows of the rectangle from top to bottom with numbe