UVA - 401 - Palindromes
2014-04-12 13:56
363 查看
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=342
题意:
辨别输入的字符串是否对称或自身镜像。
解题:
本是水题,可给行输入搞晕了。检查了半天。
cin.getline WA,但gets就能过,但gets是系统不推荐使用的。
解题用gets,其实用cin.getline。
题意:
辨别输入的字符串是否对称或自身镜像。
解题:
本是水题,可给行输入搞晕了。检查了半天。
cin.getline WA,但gets就能过,但gets是系统不推荐使用的。
解题用gets,其实用cin.getline。
#include <iostream> #include <cstring> #include <stdio.h> using namespace std; const int MAXLENGTH = 20; int main() { char LETTER_REVERSE[26] = { 'A', ' ', ' ', ' ', '3', ' ', ' ', 'H', 'I', 'L', ' ', 'J', 'M', ' ', 'O', ' ', ' ', ' ', '2', 'T', 'U', 'V', 'W', 'X', 'Y', '5' }; char NUMBER_REVERSE[10] = { ' ', '1', 'S', 'E', ' ', 'Z', ' ', ' ', '8', ' ' }; // WA // char str[100]; // while ( fgets(str, 100, stdin) != NULL ) // WA // char str[100]; // while ( cin.getline(str, MAXLENGTH) ) // WA // string str; // while ( getline(cin, str) ) char str[100]; while ( gets(str) ) { bool bMirror = true; bool bPalindrome = true; // for ( int i=0, j=str.length()-1; i<=j; i++, j-- ) for ( int i=0, j=strlen(str)-1; i<=j; i++, j-- ) { if ( str[i] != str[j] ) { bPalindrome = false; } // end if if ( isalpha(str[i]) ) { if ( LETTER_REVERSE[str[i]-'A'] != str[j] ) { bMirror = false; } // end if } // end if else { if ( NUMBER_REVERSE[str[i]-'0'] != str[j] ) { bMirror = false; } // end if } // end else } // end for cout <<str; if ( bMirror && bPalindrome ) { cout <<" -- is a mirrored palindrome." <<'\n'; } // end if else { if ( bMirror && !bPalindrome ) { cout <<" -- is a mirrored string." <<'\n'; } // end if else { if ( !bMirror && bPalindrome ) { cout <<" -- is a regular palindrome." <<'\n'; } // end if else { cout <<" -- is not a palindrome." <<'\n'; } // end else } // end else } // end else cout <<'\n'; } // end while return 0; }
相关文章推荐
- UVa401_Palindromes(小白书字符串专题)
- UVa 401 Palindromes
- UVA 401-Palindromes
- UVa 401 - Palindromes
- UVa 401 Palindromes 回文词
- UVA 401(p48)----Palindromes
- UVa-401-Palindromes
- UVa 401 Palindromes (回文串与镜像串的综合判断)
- UVa:401 - Palindromes
- uva 401 Palindromes
- UVa 401 Palindromes
- UVa 401 - Palindromes
- UVA 题目401 - Palindromes(回文词)
- UVa-401 Palindromes
- UVA - 401 Palindromes
- UVA 401 - Palindromes(判断回文串和镜像串)
- UVa 401 - Palindromes
- UVa-401-Palindromes
- (UVA)401 - Palindromes
- Palindromes UVA - 401