Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <algorithm>
- #include <vector>
- using namespace std;
- int main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios::sync_with_stdio(false);
- string s;
- cin >> s;
- int size = s.size();
- int maxstr = 0;
- int max = 0;
- for (int i = 0; i < s.size()-max ; ++i) {
- for (int j = size-i;j>0; --j) {
- string s1 = s.substr(i, j);
- if (s1.size() % 2 == 0) {
- //cout << s1 << " ";
- string s2 = s1.substr(0, j / 2);
- string s3 = s1.substr(j / 2, j / 2);
- reverse(s3.begin(), s3.end());
- if (s2 == s3) {
- maxstr = s1.size();
- if (max < maxstr) {
- max = maxstr;
- break;
- }
- }
- }
- else {
- string s2 = s1.substr(0, j / 2);
- string s3 = s1.substr(j / 2+1, j / 2);
- reverse(s3.begin(), s3.end());
- if (s2 == s3) {
- maxstr = s1.size();
- if (max < maxstr) {
- max = maxstr;
- break;
- }
- }
- }
- }
- }
- cout << max;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement