palindrome
来源:互联网 发布:网络摄像头带宽计算 编辑:程序博客网 时间:2024/04/30 14:11
palindrome
A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string"ABCDEDCBA" is apalindrome 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.
Note that O (zero) and 0 (the letter) are considered the same character and thereforeONLY 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.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.#include<stdio.h>#include<string.h>int main(){ char s[105],b[105]; int found1,found2,n; while(scanf("%s",s)!=EOF) { found1=0;found2=0; strcpy(b,s); n=strlen(s); for(int k=0;k<n/2;k++) { int t=s[k];s[k]=s[n-k-1];s[n-k-1]=t; } if(strcmp(s,b)==0) found1=1; for(int i=0;i<n;i++) { if(s[i]=='B'||s[i]=='C'||s[i]=='D'||s[i]=='F'||s[i]=='G'||s[i]=='K'||s[i]=='N'||s[i]=='P'||s[i]=='Q'||s[i]=='R'||s[i]=='4'||s[i]=='6'||s[i]=='7'||s[i]=='9') found2=0; else found2=1; } for(int j=0;j<n;j++) { if(s[j]=='E') s[j]='3'; else if(s[j]=='J') s[j]='L'; else if(s[j]=='L') s[j]='J'; else if(s[j]=='S') s[j]='2'; else if(s[j]=='Z') s[j]='5'; else if(s[j]=='2') s[j]='S'; else if(s[j]=='3') s[j]='E'; else if(s[j]=='5') s[j]='Z'; } if(strcmp(s,b)==0) found2=1; else found2=0; if(found1&&found2) printf("%s -- is a mirrored palindrome.\n",b); else if(!found1&&found2) printf("%s -- is a mirrored string.\n",b); else if(found1&&!found2) printf("%s -- is a regular palindrome.\n",b); else if(!found1&&!found2) printf("%s -- is not a palindrome.\n",b); } return 0; }
- palindrome
- Palindrome
- Palindrome
- Palindrome
- Palindrome
- Palindrome
- Palindrome
- Palindrome
- palindrome
- Palindrome
- Palindrome
- Palindrome
- Palindrome
- Palindrome
- Palindrome
- palindrome
- Palindrome
- Palindrome
- multimap的存储顺序研究
- MySQL问题解决:-bash:mysql:command not found
- MyEclipse + Maven开发Web工程的详细配置过程
- 【学习】MFC 如何处理发送给线程的消息
- 有趣的问题:C的表达式x == x,何时为假?!
- palindrome
- c++ cout 格式输出
- 关于局域网、广域网、C/S、P2P编程
- NFC (一)概述
- 0+个方便,可重复使用的jQuery代码片段
- Android之使用PackageManager取得程序的包名、图标等
- 命令_查看占用端口 netstat -ano|findstr "8080"
- SQL SERVER事务处理
- VC利用Socket实现FTP