Uva-oj Palindromes 暴力
Description
A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string is read from right to left.
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.
A mirrored palindrome is a string that meets the criteria of a regular palindrome and the criteria of a mirrored string. The string"ATOYOTA" is a mirrored palindrome because if the string is read backwards, the string is the same as the original and because if each of the characters is replaced by its reverse and the result is read backwards, the result is the same as the original string.
Of course,"A","T", "O", and "Y" are all their own reverses.
A list of all valid characters and their reverses is as follows.
| Character | Reverse | Character | Reverse | Character | Reverse |
| A | A | M | M | Y | Y |
| B | N | Z | 5 | ||
| C | O | O | 1 | 1 | |
| D | P | 2 | S | ||
| E | 3 | Q | 3 | E | |
| F | R | 4 | |||
| G | S | 2 | 5 | Z | |
| H | H | T | T | 6 | |
| I | I | U | U | 7 | |
| J | L | V | V | 8 | 8 |
| K | W | W | 9 | ||
| L | J | X | X |
Note that O (zero) and 0 (the letter) are considered the same character and therefore ONLY the letter "0" is a valid character.
Input
Input consists of strings (one per line) each of which will consist of one to twenty valid characters. There will be no invalid characters in any of the strings. Your program should read to the end of file.
Output
For each input string, you should print the string starting in column 1 immediately followed by exactly one of the following strings.
| STRING | CRITERIA |
| " -- is not a palindrome." | if the string is not a palindrome and is not a mirrored string |
| " -- is a regular palindrome." | if the string is a palindrome and is not a mirrored string |
| " -- is a mirrored string." | if the string is not a palindrome and is a mirrored string |
| " -- is a mirrored palindrome." | if the string is a palindrome and is a mirrored string |
Note that the output line is to include the -'s and spacing exactly as shown in the table above and demonstrated in the Sample Output below.
In addition, after each output line, you must print an empty line.
Sample Input
NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA
Sample Output
NOTAPALINDROME -- is not a palindrome. ISAPALINILAPASI -- is a regular palindrome. 2A3MEAS -- is a mirrored string. ATOYOTA -- is a mirrored palindrome.
Hint
use the C++'s class of string will be convenient, but not a must
第一次码这个oj 一个锻炼代码能力的题目 纯暴力
给你一个串
判断1 A regular palindrome 是否是回文串 slove1()
判断2 A mirrored string 串中字符按要求变换后 倒着读入是否与原串相同 slove2()
然后根据上述 判断 输出结果
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
using namespace std;
char a[];
int panduan1,panduan2;
map<char,char> mp;
int slove1()
{
int len=strlen(a);
int jishu=len-,gg=;;
for(int i=; i<(len)/; i++)
{
if(a[i]==a[jishu])
gg++;
jishu--;
}
if(gg==len/)
return ;
return ;
}
int slove2()
{
mp['A']='A';
mp['B']='*';
mp['C']='*';
mp['D']='*';
mp['E']='';
mp['F']='*';
mp['G']='*';
mp['H']='H';
mp['I']='I';
mp['J']='L';
mp['K']='*';
mp['L']='J';
mp['M']='M';
mp['N']='*';
mp['O']='O';
mp['P']='*';
mp['Q']='*';
mp['R']='*';
mp['S']='';
mp['T']='T';
mp['U']='U';
mp['V']='V';
mp['W']='W';
mp['X']='X';
mp['Y']='Y';
mp['Z']='';
mp['']='';
mp['']='S';
mp['']='E';
mp['']='*';
mp['']='Z';
mp['']='*';
mp['']='*';
mp['']='';
mp['']='*';
int len=strlen(a);
int jishu=len-;
int gg=;
for(int i=; i<len; i++)
{
if(a[i]==mp[a[jishu]])
gg++;
jishu--;
}
if(gg==len)
return ;
return ;
}
int main()
{
while(scanf("%s",a)!=EOF)
{
//getchar();
panduan1=slove1();
panduan2=slove2();
if(panduan1)
{
if(panduan2)
cout<<a<<" -- is a mirrored palindrome."<<endl;
else
cout<<a<<" -- is a regular palindrome."<<endl;
}
else
{
if(panduan2)
cout<<a<<" -- is a mirrored string."<<endl;
else
cout<<a<<" -- is not a palindrome."<<endl;
}
cout<<endl;
memset(a,,sizeof(a)); }
return ;
}
Uva-oj Palindromes 暴力的更多相关文章
- UVA.725 Division (暴力)
UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...
- 10年省赛-Greatest Number (二分+暴力) + 12年省赛-Pick apples(DP) + UVA 12325(暴力-2次枚举)
题意:给你n个数,在里面取4个数,可以重复取数,使和不超过M,求能得到的最大的数是多少: 思路:比赛时,和之前的一个题目很像,一直以为是体积为4(最多选择四次)的完全背包,结果并不是,两两求和,然后二 ...
- Codeforces Round #315 (Div. 1) A. Primes or Palindromes? 暴力
A. Primes or Palindromes?Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3261 ...
- Codeforces Round #315 (Div. 2) C. Primes or Palindromes? 暴力
C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input st ...
- uva 401.Palindromes
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVa OJ 175 - Keywords (关键字)
Time limit: 3.000 seconds限时3.000秒 Problem问题 Many researchers are faced with an ever increasing numbe ...
- UVa OJ 197 - Cube (立方体)
Time limit: 30.000 seconds限时30.000秒 Problem问题 There was once a 3 by 3 by 3 cube built of 27 smaller ...
- UVa OJ 140 - Bandwidth (带宽)
Time limit: 3.000 seconds限时3.000秒 Problem问题 Given a graph (V,E) where V is a set of nodes and E is a ...
- BestCoder Round #50 (div.1) 1002 Run (HDU OJ 5365) 暴力枚举+正多边形判定
题目:Click here 题意:给你n个点,有多少个正多边形(3,4,5,6). 分析:整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可. #include ...
随机推荐
- 【WXS全局对象】Date
属性: 名称 说明 Date.parse( [dateString] ) 解析一个日期时间字符串,并返回 1970/1/1 午夜距离该日期时间的毫秒数. Date.UTC(year,month,day ...
- 牛客练习赛26:D-xor序列(线性基)
链接:牛客练习赛26:D-xor序列(线性基) 题意:小a有n个数,他提出了一个很有意思的问题:他想知道对于任意的x, y,能否将x与这n个数中的任意多个数异或任意多次后变为y 题解:线性基 #inc ...
- [C++ map & dp]codeforces 960F. Pathwalks
题目传送门:960F 思路: 题目给人的感觉很像最长上升子序列,自然而然想到用dp的思路去处理 题目中给的限制条件是,要接上前面的边,前面的边权一定要小于当前的边权(题目按照输入的顺序,因此只找前面的 ...
- Elasticsearch 排序插件的开发
直接观察到的几个问题 简单expression脚本的执行效率 > java 插件,10000条数据可以测试出1ms左右的差距. Es会不断调用newScript来创建"足够多" ...
- Jquery复选框
Jquery复选框 1.checkbox list选择 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E ...
- HADOOP docker(四):安装hive
1.hive简介2.安装hive2.1 环境准备2.1.1 下载安装包2.1.2 设置hive用户的环境变量2.1.3 hive服务端配置文件2.1.4 hive客户端配置文件2.1.4 分发hive ...
- selenium元素定位不到之iframe---基于python
我们在使用selenium的18中定位方式的时候,有时会遇到定位不上的问题,今天我们就来说说导致定位不上的其中一个原因---iframe 问题描述:通过firebug查询到相应元素的id或name等, ...
- python切片详解
先从原理上分析切片运算: list的切片,内部是调用__getitem__,__setitem__,__delitem__和slice函数.而slice函数又是和range()函数相关的. 给切片传递 ...
- lintcode-42-最大子数组 II
42-最大子数组 II 给定一个整数数组,找出两个 不重叠 子数组使得它们的和最大. 每个子数组的数字在数组中的位置应该是连续的. 返回最大的和. 注意事项 子数组最少包含一个数 样例 给出数组 [1 ...
- iOS-获取webView的高度
- (void)webViewDidFinishLoad:(UIWebView *)wb{ //方法1 CGFloat documentWidth = [[wb stringByEvaluatingJ ...