Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <algorithm>
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <iomanip>
  6. #include <stdio.h>
  7. #include <bitset>
  8. #include <vector>
  9. #include <string>
  10. #include <cmath>
  11. #include <queue>
  12. #include <deque>
  13. #include <map>
  14. #include <set>
  15.  
  16. using namespace std;
  17.  
  18. #define pb push_back
  19. #define mp make_pair
  20. #define S second
  21. #define F first
  22.  
  23. const int INF = 2e9;
  24. const long long INFLL = 2e18;
  25. const int MOD = 1e9 + 7;
  26.  
  27. int main()
  28. {
  29.     //freopen("input.txt", "r" , stdin);
  30.     //freopen("output.txt", "w" , stdout);
  31.     //
  32.     freopen("locker.in", "r" , stdin);
  33.     freopen("locker.out", "w" , stdout);
  34.  
  35.     string s;
  36.     cin >> s;
  37.     vector < int > a;
  38.     for (int i = 0; i < s.length() / 2; i++){
  39.         if (s[i] != s[s.length() - i - 1]){
  40.             a.push_back(i);
  41.             a.push_back(s.length() - i - 1);
  42.         }
  43.     }
  44.  
  45.     if (a.size() == 0){
  46.         cout << "YES";
  47.         return 0;
  48.     }
  49.  
  50.     if (a.size() > 10){
  51.         cout << "NO";
  52.         return 0;
  53.     }
  54.  
  55.     string t;
  56.  
  57.     if (s.length() % 2 == 1){
  58.         a.push_back((s.length()) / 2);
  59.     }
  60.  
  61.     for (int i = 0; i < a.size(); i++){
  62.         for (int j = i + 1; j < a.size(); j++){
  63.             int x = a[i] , y = a[j];
  64.             swap(s[x] , s[y]);
  65.             t = s;
  66.             reverse(t.begin() , t.end());
  67.             if (s == t){
  68.                 cout << "YES";
  69.                 return 0;
  70.             }
  71.             swap(s[x] , s[y]);
  72.         }
  73.     }
  74.     cout << "NO";
  75.  
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement