Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 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. bool flag = true;
  14. int index;
  15. int cnt = 0;
  16.  
  17. for (int a = 0; a < input_n; a++) {
  18. arr[a] = input_s[a];
  19. arr[a + input_n] = input_s[a];
  20.  
  21. if (input_s[a] == input_s[input_n - 1] && flag == true) {
  22. index = a;
  23. flag = false;
  24. }
  25. }
  26.  
  27.  
  28.  
  29. for (int a = index; a < index + input_n; a++) {
  30. if (arr[a] == input_s[input_n + index - a - 1]) {
  31. cnt++;
  32. }
  33. }
  34.  
  35. cout << ((cnt == input_n) ? index : -1);
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement