Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main() {
  6. string input_s;
  7. int input_n;
  8. cin >> input_n;
  9. cin >> input_s;
  10.  
  11. int size = input_n * 2;
  12. char* arr = new char[size];
  13.  
  14. char query = input_s[input_n - 1];
  15. int index;
  16. int cnt = 0;
  17.  
  18. for (int a = 0; a < input_n; a++) {
  19. arr[a] = input_s[a];
  20. arr[a + input_n] = input_s[a];
  21. if (input_s[a] == query) {
  22. index = a;
  23. }
  24. }
  25.  
  26.  
  27. for (int a = index; a < index + input_n; a++) {
  28. if (arr[a] == input_s[input_n + index - a - 1]) {
  29. cnt++;
  30. }
  31. }
  32.  
  33. cout << ((cnt == input_n) ? cnt - 1 : -1);
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement