Codeforces 691B. s-palindrome

题目链接:http://codeforces.com/problemset/problem/691/B

题意:

给你一个字符串,需要让你判断这个字符串是否为镜像串,即关于中心轴对称.

思路:

常量数组的运用,需要注意的是当字符串包含奇数个字符时最中间的那个字符不要忘记判断.

代码:

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 const int MAXN = 100000;
 6 typedef long long LL;
 7 
 8 char str[] = "-d-b----------oqp----vwx--A------HI---M-O----TUVWXY-";
 9 
10 char chage(char c) {
11     if(islower(c)) return str[c - 'a'];
12     return str[c - 'A' + 26];
13 }
14 
15 int main() {
16     ios_base::sync_with_stdio(0); cin.tie(0);
17     char ss[1007] = {0};
18     cin >> ss;
19     int len = strlen(ss);
20     int ok = 1;
21     for(int i = 0; i < (len + 1) / 2; i++) if(ss[i] != chage(ss[len - i - 1])) ok = 0;
22     if(ok) cout << "TAK" << endl;
23     else cout << "NIE" << endl;
24     return 0;
25 }

 

posted @ 2016-09-03 16:27  vrsashly  阅读(180)  评论(0编辑  收藏  举报