POJ 1590 Palindromes 肯爹题

本题就是专门肯人的题目,给出的列子也是故意误导人的。

其实就考一点:没有mirror的字母存在的时候就可以判定整个字符串不是mirror!

如下面的mirrored string的叙述:

A mirrored string is a string for which when each of the elements of the string is changed to its reverse (if it has a reverse) and the string is read backwards the result is the same
as the original string. For example, the string "3AIAE" is a mirrored string because "A" and "I" are their own reverses, and "3" and "E" are each others‘ reverses.

愣是没说没有mirror的时候如何判断,要自己猜测。

题意重要,聪明地判断题意也很重要。高端人才,各种陷阱,各种细节都要考虑到极致了。

本来找Palindrome的题目做做,看到这么简单本来不想做的,花了几分钟敲出代码来,居然WA,没想到也学到东西了。不能小看任何所谓“水”题啊。

#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <limits.h>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

bool mirror, palin;
char tbl[256];

void initTable()
{
	memset(tbl, 0, sizeof(tbl));
	tbl['A'] = 'A';
	tbl['E'] = '3';
	tbl['H'] = 'H';
	tbl['I'] = 'I';
	tbl['J'] = 'L';
	tbl['L'] = 'J';
	tbl['S'] = '2';
	tbl['M'] = 'M';
	tbl['O'] = 'O';
	tbl['T'] = 'T';
	tbl['U'] = 'U';
	tbl['V'] = 'V';
	tbl['W'] = 'W';
	tbl['X'] = 'X';
	tbl['Y'] = 'Y';
	tbl['1'] = '1';
	tbl['Z'] = '5';
	tbl['2'] = 'S';
	tbl['3'] = 'E';
	tbl['5'] = 'Z';
	tbl['8'] = '8';
}

void getPalinMirror(string &s)
{
	palin = true;
	for (int i = 0, j = (int)s.size()-1; i < j && palin; i++, j--)
	{
		if (s[i] != s[j]) palin = false;

	}
	mirror = true;
	for (int i = 0, j = (int)s.size()-1; i <= j && mirror; i++, j--)
	{
		if (!tbl[s[i]] || s[i] != tbl[s[j]]) mirror = false;
	}
}

int main()
{
	string s;
	initTable();
	while (cin>>s)
	{
		getPalinMirror(s);
		printf("%s", s.c_str());
		if (!palin && !mirror) puts(" -- is not a palindrome.");
		else if (palin && !mirror) puts(" -- is a regular palindrome.");
		else if (!palin && mirror) puts(" -- is a mirrored string.");
		else if (palin && mirror) puts(" -- is a mirrored palindrome.");
		putchar('\n');
	}
	return 0;
}

POJ 1590 Palindromes 肯爹题

时间: 2024-11-08 18:54:11

POJ 1590 Palindromes 肯爹题的相关文章

肯爹的 StringUtils.isNumeric(String str)

在项目中遇到一处bug,调试的结果竟然是StringUtils.isNumeric(String str) 在捣鬼(采用的是org.apache.commons.lang.StringUtils),下面的代码是判断一个参数非空,且为整数: if(StringUtils.isNumeric(str) && StringUtils.isNotBlank(str)){ // do sth } 在简单不过的代码,却隐藏着bug ! 因为如果 str = "-1"; String

poj 2369 Permutations 置换水题

找循环节求lcm就够了,若答案是12345应该输出1,被坑了下. #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<cmath> using namespace std; #define INF 0x3FFFFFF #define MAXN 2222 #define eps 1e-6 i

poj 1006:Biorhythms(水题,经典题,中国剩余定理)

Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 110991   Accepted: 34541 Description Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical,

poj 1002:487-3279(水题,提高题 / hash)

487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 236746   Accepted: 41288 Description Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phras

POJ 1488 Tex Quotes --- 水题

POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 Tex Quotes --- 水题 */ #include <cstdio> #include <cstring> int main() { #ifdef _LOCAL freopen("D:\\input.txt", "r", stdin); #

poj 1003:Hangover(水题,数学模拟)

Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 99450   Accepted: 48213 Description How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're as

Poj 1094 拓扑排序 水题

Sad..这么水的题WA了无数发,题目要看仔细啊,留下来做个警告把 #include <cstdio> #include <cstring> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #include <cstdlib> #include <list> #i

POJ 3342 树形DP入门题

题目意思和POJ2342一样,只是多加了一个条件,如果最大方案数唯一,输出Yes,不唯一输出No dp的是时候多加一个变量记录答案是否唯一即可 #include "stdio.h" #include "string.h" #include "vector" using namespace std; struct node { int fa; vector<int>child; }data[210]; struct comp { int

POJ 1947 树形DP入门题

给出N个点,N-1个关系,建出树形图,问最少减去几个边能得到节点数为P的树.典型树形DP题 dp[cur][j] :记录cur结点,要得到一棵j个节点的子树去掉的最少边数 转移方程用的背包的思想 对当前树的每一个子树进行计算 砍掉此子树:   dp[cur][j]=dp[cur][j]+1; 不砍掉:           for (l=0;l<=j;l++)  dp[cur][j]=Min(dp[cur][j],dp[cur][l]+dp[next][j-l]); 枚举从该树中留l个节点其他由新