博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVa 401 Palindromes
阅读量:7112 次
发布时间:2019-06-28

本文共 1479 字,大约阅读时间需要 4 分钟。

题目大意: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;
}

  

==============================================================================
本文转自被遗忘的博客园博客,原文链接:http://www.cnblogs.com/rollenholt/archive/2012/03/21/2410753.html,如需转载请自行联系原作者
你可能感兴趣的文章
linux grep awk sed find cut
查看>>
TPYBoardv202自制微信远程智能温湿度计
查看>>
投诉数千起 共享单车押金为啥难退
查看>>
搭建一个类似线上的线下测试环境
查看>>
go接口测试
查看>>
iOS7.0以上(含7.0)xib中UILabel自适应高度
查看>>
Hbase基本语句用法
查看>>
python 操作redis
查看>>
简单的Linux ***软件PPTP的安装
查看>>
20.目录创建与目录删除
查看>>
sed学习笔记-3(命令DPhHgGxbtnN)
查看>>
sed 获取shell变量和branch(b)分支的用法
查看>>
Python常用函数
查看>>
设计模式——策略模式(Strategy Pattern)
查看>>
Android Fragment使用(一) 基础篇 温故知新
查看>>
mongodb制作副本集 以及用户名密码认证
查看>>
apache高级配置
查看>>
WSUS客户端更新补丁失败(1)
查看>>
【验证】mysql root密码恢复
查看>>
PHP面向对象编程(2)——类的实例化
查看>>