Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <cmath>
  5. #include <vector>
  6. #include <fstream>
  7. #include <utility>
  8. #include <stdio.h>
  9. #include <map>
  10.  
  11. using namespace std;
  12.  
  13. map<char,int>m;
  14. vector<int>sh;
  15. string s;
  16.  
  17. int main()
  18. {
  19. //freopen("input.txt" , "r" , stdin);
  20. //freopen("output.txt" , "w" , stdout);
  21. freopen("locker.in" , "r" , stdin);
  22. freopen("locker.out" , "w" , stdout);
  23. if (s.size()==1)
  24. {
  25. cout<<"YES";
  26. return 0;
  27. }
  28. cin>>s;
  29. for (int i=0; i<s.size(); i++)
  30. {
  31. m[s[i]]++;
  32. }
  33. int kc=0;
  34. for (int i = 0; i<s.size(); i++)
  35. {
  36. if (m[s[i]]%2==1)
  37. {
  38. kc++;
  39. m[s[i]]=0;
  40. }
  41. }
  42. for (int i=0; i<s.size(); i++)
  43. {
  44. m[s[i]]++;
  45. }
  46. if (s.size()%2==0 && kc>0)
  47. {
  48. cout<<"NO";
  49. return 0;
  50. }
  51. if (s.size()%2==1 && kc>1 && m[s[s.size()/2]]%2!=0)
  52. {
  53. cout<<"NO";
  54. return 0;
  55. }
  56. int n=s.size()/2;
  57. if (s.size()%2==0)
  58. n--;
  59. for (int i=0; i<=n; i++)
  60. {
  61. if (s[i]!=s[s.size()-i-1])
  62. sh.push_back(i);
  63. }
  64. if (sh.size()<=2)
  65. {
  66. swap(s[sh[0]],s[sh[1]]);
  67. if (s[sh[0]]==s[s.size()-sh[0]-1] && s[sh[1]]==s[s.size()-sh[1]-1])
  68. cout<<"YES";
  69. else cout<<"NO";
  70. }
  71. else cout<<"NO";
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement