UVa-Palindromes
C++代码:
#include <cstdio>
#include <cstring>
int main()
{
char a[3000];
char s[3000];
char str[]={'A','*','*','*','3',
'*','*','H','I','L',
'*','J','M','*','O',
'*','*','*','2','T',
'U','V','W','X','Y',
'5','0','1','S','E','*',
'Z','*','*','8','*'};
while(scanf("%s",a)!=EOF)
{
strcpy(s,a);
int isp=0,ism=0;
int len=strlen(s);
int i,j;
for(i=0,j=len-1;i<=j;++i,--j)
{
if((s[i]=='0'||s[i]=='O')&&(s[j]=='0'||s[j]=='O'))
continue;
else
if(s[i]!=s[j])
break;
}
if(i>j)isp=1;
for(i=0;i<len;++i)
{
if(s[i]>='A'&&s[i]<='Z')
s[i]=str[s[i]-'A'];
else
s[i]=str[s[i]-'0'+26];
}
for(i=0,j=len-1;i<len;++i,--j)
{
if((a[i]=='0'||a[i]=='O')&&(s[j]=='0'||s[j]=='O'))
continue;
else
if(a[i]!=s[j])
break;
}
if(i==len)
ism=1;
if(isp==0&&ism==0)
printf("%s -- is not a palindrome.\n\n",a);
else
if(isp==1&&ism==0)
printf("%s -- is a regular palindrome.\n\n",a);
else
if(isp==0&&ism==1)
printf("%s -- is a mirrored string.\n\n",a);
else
printf("%s -- is a mirrored palindrome.\n\n",a);
}
return 0; }
UVa-Palindromes的更多相关文章
- UVA - 11584 Partitioning by Palindromes[序列DP]
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...
- UVA 11584 一 Partitioning by Palindromes
Partitioning by Palindromes Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %l ...
- UVa 353 - Pesky Palindromes
称号:字符串统计回文子的数量. 分析:dp,暴力.因为数据是小,直接暴力可以解决. 说明:(UVa最终评出800该). #include <iostream> #include <c ...
- uva 11584 Partitioning by Palindromes 线性dp
// uva 11584 Partitioning by Palindromes 线性dp // // 题目意思是将一个字符串划分成尽量少的回文串 // // f[i]表示前i个字符能化成最少的回文串 ...
- 区间DP UVA 11584 Partitioning by Palindromes
题目传送门 /* 题意:给一个字符串,划分成尽量少的回文串 区间DP:状态转移方程:dp[i] = min (dp[i], dp[j-1] + 1); dp[i] 表示前i个字符划分的最少回文串, 如 ...
- uva 401.Palindromes
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 11584 Partitioning by Palindromes (字符串区间dp)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- 【UVa】Partitioning by Palindromes(dp)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=27&page=sh ...
- UVa 11584 - Partitioning by Palindromes(线性DP + 预处理)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- uva 401 Palindromes 解题报告
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- timesetevent与timekillevent的用法
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs ...
- GreenDao数据库结构升级
1.先用GreenDao工具类编写自动创建代码,按照升级后的最新数据库结构来编写 2.GreenDao工具自动生成的代码覆盖到项目里去 3.在项目里找到对应的自动生成的数据库DaoMaster类 在D ...
- Swift - 创建并设置背景(SpriteKit游戏开发)
1,先把背景图片bg.jpg,bg@2x.jpg直接拖进Images.xcassets中 2,设置如下代码(背景图直接铺满整个屏幕) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
- ASP.NET - 记录错误日志
不需要像log4net/Nlog/Common Logging配置,简单好用. 不用增加声明logger对象,可记录当前执行状况. 可以定义 维护功能模板的开发人员,以便用功能模块对于开发人员. 出处 ...
- C语言sendto()函数-经socket传送数据以及recvfrom函数《转》
相关函数:send, sendmsg, recv, recvfrom, socket 头文件:#include <sys/types.h> #include <sys/socke ...
- Android——与查询联系人相关的3张表
- [置顶] android之Notification版本兼容性问题
首先先来创建一个notification提示 //概要 String tickerText = context.getResources().getText(R.string.app_name).to ...
- Android颜色转换工具类ColorUtil
项目中需要根据ScrollView的滚动距离来动态设置Topbar的背景透明度,网上有类似的开源库FadingActionBar,使用的是ActionBar做的.而我的项目中并没有使用ActionBa ...
- pc2日记——有惊无险的第二天2014/08/29
今天下午如期的用pc2进行了第二场比赛.因为昨天的出错经历和早上充足的准备,下午的比赛尽管在開始的时候出了点小小的问题,但总的来说还是非常成功的. 早上八点过去504開始又一次配置client,由于开 ...
- CSS中float属性和clear属性的一些笔记
在学习CSS的最后一部分内容中,float属性和clear属性比较难以用语言描述,因此在笔记本中无法准确的记录这两个属性的用法.所以在博客园上以图文的形式记录这两种属性的特征,以备以后查阅. 首先,定 ...