UVa 401 Palindromes

简介:

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#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;
}

  


目录
相关文章
|
算法 索引
LeetCode 214. Shortest Palindrome
给定一个字符串 s,你可以通过在字符串前面添加字符将其转换为回文串。找到并返回可以用这种方式转换的最短回文串。
59 0
LeetCode 214. Shortest Palindrome
AtCoder Beginner Contest 214 F - Substrings(subsequence DP)
AtCoder Beginner Contest 214 F - Substrings(subsequence DP)
76 0
|
机器学习/深度学习
Uva - 12050 Palindrome Numbers【数论】
题目链接:uva 12050 - Palindrome Numbers   题意:求第n个回文串 思路:首先可以知道的是长度为k的回文串个数有9*10^(k-1),那么依次计算,得出n是长度为多少的串,然后就得到是长度为多少的第几个的回文串了,有个细节注意的是, n计算完后要-1! 下面给出A...
817 0
[LeetCode] Shortest Palindrome
The idea is to find the longest palindromic substring of s that begins with s[0]. Then take the remaining susbtring, reverse it and append it to the beginning of s.
801 0

热门文章

最新文章