Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. struct out{
  5. int f;
  6. int s ;
  7. int len;
  8. };
  9. out CenterDiscustion(int first,int second, string sub){
  10. int res = 0 , f1 = first , s1 = second;
  11. while(f1 >= 0 && sub[f1] == sub[s1]){
  12. res = s1 - f1 + 1;
  13. f1--;
  14. s1++;
  15. }
  16. out l {
  17. f1 + 1, s1 - 1 , res};
  18. return l ;
  19. }
  20. string StringReturner(string s){
  21. out len1 , len2 , res{0 , 0 , 0};
  22. if ( s.length() < 1) return "";
  23. int f = 0 , se = 0;
  24. for(int i = 0; i < s.size(); i++){
  25. len1 = CenterDiscustion(i , i , s);
  26. len2 = CenterDiscustion(i, i + 1, s);
  27. if (res.len < len1.len){
  28. res = len1;
  29. }
  30. if (res.len < len2.len){
  31. res = len2;
  32. }
  33. }
  34. string re = s.substr(res.f , res.len);
  35. return re;
  36. }
  37. int main() {
  38.  
  39. string a = "blll";
  40. string k = StringReturner(a);
  41. cout << k;
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement