HDU 1318 palindromes (palindrome word)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1318

Test Instructions Analysis: Input each line contains a string to determine whether this string is a palindrome or mirror string. On the surface, the problem is somewhat complicated, and if you can skillfully use a character array, the code is quite concise.

/*Palindromestime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) total submission (s): 657 Accepted Submission (s): 250Problem Descriptiona Regular palindrome is a string of numbers or letters this is the same forw ard as backward. For example, the string "ABCDEDCBA" was a palindrome because it was the same when the string was read from left to right as W Hen the string is a read from right to left. A mirrored string is a string for which when each of the elements of the string was changed to its reverse (if it had a rev Erse) and the string is read backwards the result is the same as the original string. For example, the string "3AIAE" was a mirrored string because "a" and "I" are their own reverses, and "3" and "E" were 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 was read backwards, the string is theSame as the original and because if each of the characters are replaced by their reverse and the result is read backwards, th E result is the same as the original string. Of course, "A", "T", "O", and "Y" is all their own reverses. A List of all valid characters and their reverses are as follows.                   Character Reverse Character Reverse Character Reverse a a m m y y B                   N Z 5 C o 1 1 D                   P 2 S E 3 Q 3 E F R         4 G S 2 5 Z h T T 6 I         I u u 7 J L v v 8 8 K W W 9 L J X xnote that O (zero) and 0 (the letter) is consIdered the same character and therefore only the ' 0 ' is a valid character. Inputinput consists of strings (one per line) each of the which would consist of one to twenty valid characters. There'll be is no invalid characters in any of the strings. Your program should read to the end of file. Outputfor each input string, should print the string starting in column 1 immediately followed by exactly one of the F Ollowing strings. "--is not a palindrome." If the string was not a palindrome and was not a mirrored string "– is a regular palindrome." I f The string is a palindrome and was not a mirrored string "– is a mirrored string." If the string was not a palindrome a D is a mirrored string "--was a mirrored palindrome." If the string is a palindrome and was a mirrored string Note that th E output line was to include the-' s and spacing exactly as shown in the table above and demonstrated in the Sample output Below.  In addition, after the output line, you must print a empty line. SaMple inputnotapalindrome isapalinilapasi 2a3meas atoyota Sample outputnotapalindrome-is not a palindrome. Isapalinilapasi--is a regular palindrome.2a3meas--is a mirrored string. Atoyota--is a mirrored palindrome. Sourcesouth Central USA 1995*/#include<cstdio>#include<cstring>#include<cctype>Const Char* Rev ="A 3 HIL JM O 2tuvwxy51se Z 8";Const Char* msg[] = {"Not a palindrome","a regular palindrome","a mirrored string","a mirrored palindrome"};CharRCharch) {    if(Isalpha (CH))returnrev[ch-'A']; returnRev[ch-'0'+ -];}intMain () {Chars[ -];  while(~SCANF ("%s", s)) {        intLen =strlen (s); intp =1, M =1;  for(inti =0; I < (len+1)/2; i++){            if(S[i]! = s[len-i-1]) p =0; if(R (s[i])! = s[len-i-1]) m =0; } printf ("%s--is%s.\n\n", S, msg[m*2+p]); }    return 0;}

HDU 1318 palindromes (palindrome word)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.