UVa-401 Palindromes回文词
2024-10-08 00:34:25
虽然是水题,但是容易错。参照了紫书的代码可以写的很简洁。主要还是注意常量数组的使用,能让代码变得简单许多
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <stack>
#include <math.h>
#pragma warning ( disable : 4996 ) using namespace std; int Max( int a, int b ) { return a>b?a:b; }
int Min( int a, int b ) { return a>b?b:a; } const int inf = 0x3f3f3f3f;
const int maxn = + ;
const char T[] = "A...3..HIL.JM.O...2TUVWXY51SE.Z..8.";
char test[]; char getM( char c )
{
if (isalpha(c)) return T[c-'A'];
else return T[c-''+];
}
int main()
{
while ( ~scanf("%s", test) )
{
int len = strlen(test);
bool isP = true, isM = true;
for ( int i = ; i < (len+) / ; i++ )
{
if ( test[i] != test[len--i] ) isP = false;
if ( getM(test[i]) != test[len--i] ) isM = false;
}
if ((!isP)&&(!isM)) printf( "%s -- is %s\n\n", test, "not a palindrome." );
if (isP&&(!isM)) printf( "%s -- is %s\n\n", test, "a regular palindrome." );
if ((!isP)&&isM) printf( "%s -- is %s\n\n", test, "a mirrored string." );
if (isP&&isM) printf( "%s -- is %s\n\n", test, "a mirrored palindrome." );
}
return ;
}
最新文章
- python之最强王者(2)——python基础语法
- C# Winform防止一个程序重复运行
- Android原生(Native)C开发之一:环境搭建篇
- HighChart报表之饼图
- Notes on &#39;Selective Search For Object Recognition&#39;
- linux 打开远程samba服务器
- CentOS使用ufw的方法
- java.lang.OutOfMemoryError: Java heap space错误及处理办法
- 2.x ESL第二章习题 2.8
- leetcode算法刷题(二)——动态规划(一)
- Docker 三剑客之 Compose
- 在VCS仿真器中使用FSDB
- Django(四) ORM 外键操作及初识Ajax
- SpringMVC从认识到细化了解
- 容器技术|Docker三剑客之docker-compose
- Robust Real-time Object Detection学习
- Spring源码阅读(四)
- SSRF攻击-运用gopher协议构造POST包--emmmm(http://10.112.68.215:10004/index.php?action=login)
- 微服务之kong+consul(二)
- absolute绝对定位的非绝对定位用法