Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <cmath>
  4. #include <string>
  5. #include <algorithm>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. int main() {
  12. #ifdef _DEBUG
  13. freopen("input.txt", "r", stdin);
  14. freopen("output.txt", "w", stdout);
  15. #endif
  16. ios::sync_with_stdio(false);
  17. string s;
  18. cin >> s;
  19. int size = s.size();
  20. int maxstr = 0;
  21. int max = 0;
  22. for (int i = 0; i < s.size()-max ; ++i) {
  23.  
  24. for (int j = size-i;j>0; --j) {
  25. string s1 = s.substr(i, j);
  26. if (s1.size() % 2 == 0) {
  27. //cout << s1 << " ";
  28. string s2 = s1.substr(0, j / 2);
  29. string s3 = s1.substr(j / 2, j / 2);
  30. reverse(s3.begin(), s3.end());
  31.  
  32. if (s2 == s3) {
  33. maxstr = s1.size();
  34. if (max < maxstr) {
  35. max = maxstr;
  36. break;
  37. }
  38. }
  39. }
  40. else {
  41. string s2 = s1.substr(0, j / 2);
  42. string s3 = s1.substr(j / 2+1, j / 2);
  43. reverse(s3.begin(), s3.end());
  44.  
  45. if (s2 == s3) {
  46. maxstr = s1.size();
  47. if (max < maxstr) {
  48. max = maxstr;
  49. break;
  50. }
  51. }
  52. }
  53. }
  54. }
  55. cout << max;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement