Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 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.  
  22.  
  23.  
  24. for (int a = 0; a < input_n; a++) {
  25.  
  26. if (input_s[a] == input_s[input_n - 1] && flag == true) {
  27. index = a;
  28.  
  29. for (int b = index; b < index + input_n; b++) {
  30. if (arr[b] == input_s[input_n + index - b - 1]) {
  31. cnt++;
  32. }
  33. }
  34.  
  35. if (cnt == input_n) {
  36. cout << index;
  37. flag = false;
  38. }
  39. index = 0;
  40. cnt = 0;
  41. }
  42. else if (flag == false) break;
  43. }
  44.  
  45. if (flag == true) {
  46. cout << -1;
  47. }
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement