Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- string input_s;
- int input_n;
- cin >> input_n;
- cin >> input_s;
- int size = input_n * 2;
- char* arr = new char[size];
- bool flag = true;
- int index;
- int cnt = 0;
- for (int a = 0; a < input_n; a++) {
- arr[a] = input_s[a];
- arr[a + input_n] = input_s[a];
- }
- for (int a = 0; a < input_n; a++) {
- if (input_s[a] == input_s[input_n - 1] && flag == true) {
- index = a;
- for (int b = index; b < index + input_n; b++) {
- if (arr[b] == input_s[input_n + index - b - 1]) {
- cnt++;
- }
- }
- if (cnt == input_n) {
- cout << index;
- flag = false;
- }
- index = 0;
- cnt = 0;
- }
- else if (flag == false) break;
- }
- if (flag == true) {
- cout << -1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement