uva 401.Palindromes
生活随笔
收集整理的這篇文章主要介紹了
uva 401.Palindromes
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題目鏈接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=342
題目意思:給出一段字符串(大寫字母+數(shù)字組成)。判斷是否為回文串 or 鏡像串 or 回文鏡像串 or 什么都不是。每個(gè)字母的鏡像表格如下
?
| 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 | ? | ? |
?
注意是沒有數(shù)字0的哦。(該題,數(shù)字 0 與字母 O 看成是一樣的)
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 using namespace std; 6 7 const int maxn = 1000 + 5; 8 char mirror[] = "A 3 HIL JM O 2TUVWXY51SE Z 8 "; 9 const char *msg[4] = {" -- is not a palindrome.", " -- is a regular palindrome.", " -- is a mirrored string.", " -- is a mirrored palindrome."}; 10 char s[maxn]; 11 12 char change(char ch) 13 { 14 if (ch >= 'A' && ch <= 'Z') 15 return mirror[ch-'A']; 16 return mirror[ch-'0'+25]; 17 } 18 19 int main() 20 { 21 #ifndef ONLINE_JUDGE 22 freopen("in.txt", "r", stdin); 23 #endif // ONLINE_JUDGE 24 25 while (scanf("%s", s) != EOF) { 26 int len = strlen(s); 27 int p = 1, m = 1; 28 29 for (int i = 0; i < len; i++) { 30 if (s[i] != s[len-i-1]) p = 0; 31 if (change(s[i]) != s[len-i-1]) m = 0; 32 } 33 printf("%s%s\n\n", s, msg[p+m*2]); 34 } 35 return 0; 36 }
?
轉(zhuǎn)載于:https://www.cnblogs.com/windysai/p/5348481.html
總結(jié)
以上是生活随笔為你收集整理的uva 401.Palindromes的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转]JAVA中Action层, Ser
- 下一篇: struts2笔记01-环境搭建