题目链接: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 }

 

相关文章:

  • 2022-12-23
  • 2021-09-24
  • 2022-01-14
  • 2022-12-23
  • 2022-03-01
  • 2022-01-03
  • 2021-06-01
  • 2021-06-10
猜你喜欢
  • 2021-11-16
  • 2021-06-03
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案