<常量数组> UVA 401
来源:互联网 发布:linux 获取ntp时间 编辑:程序博客网 时间:2024/06/14 09:52
UVA 401:
输入一个字符串,判断它是否是回文串以及镜像串。输入字符串保证不含数字0.所谓回文串,就是反转以后和原串相同,如abba和madam. 所谓镜像串,就是左右镜像后与原串相同,如2S和3AIAE.注意,并不是每个字符在镜像后都能够得到一个合法字符。
代码:
#include <cstdio>#include <cstring>#include <ctype.h>using namespace std;const char * rev = "A 3 HIL JM O 2TUVMXY51SE Z 8 ";const char * msg[] = {"not a palindrome", "a regular palindrome", "a mirrored string", "a mirrored palindrome"};char r (char ch){ if(isalpha(ch)) return rev[ch-'A']; else return rev[ch-'0'+25];}int main(){ char s[30]; while(scanf("%s", s) != EOF) { int len = strlen(s); int p=1, m=1; for(int i=0; i<(len+1)/2; i++) { char c = r(s[i]); //putchar(c); if(s[i] != s[len-1-i]) p = 0;//不是回文串 if(c != s[len-1-i]) { m = 0;//不是镜像串 } } //printf("p=%d, m=%d\n", p, m); printf("%s -- is %s.\n\n", s, msg[m*2+p]); } return 0;}
0 0
- <常量数组> UVA 401
- UVa 401 Palindromes(常量数组+遍历)
- <常量数组的应用> UVA 10082 WERTYU
- UVa - 10082 - WERTYU (常量数组的使用)
- 为什么数组是常量
- 变量和常量,数组
- 字符串常量、数组
- 指针常量,数组打印
- 常量数组处理字符串
- PHP7之常量数组
- 指针常量/常量指针&指针数组/数组指针
- 指针数组,数组指针,常量指针,指针常量
- 指针常量与常量指针,指针数组与数组指针
- 指针数组与数组指针,指针常量与常量指针
- 字符串常量与字符串数组
- 数组字符串常量的存储
- php 数组常量的定义
- thinkphp3.2自定义常量数组
- Android Studio Plugin-Translate English to Chinese
- 26_XML DOM - Document 对象
- Eclipse配置TomCat发布Web工程,缺少lib文件夹和jar包
- C++ STL实例(一)
- 27_XML DOM - DocumentImplementation 对象
- <常量数组> UVA 401
- 28_XML DOM - DocumentType 对象
- NodeJS、NPM安装配置步骤(windows7 64位)
- python 生成器yield
- 29_XML DOM - ProcessingInstruction 对象
- 2016/5/18
- hibernate 学习(2)
- 30_XML DOM - Element 对象
- qt4环境搭建