Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. char s[300];
  8. cin.getline( s , 300 ) ;
  9. int lung = strlen ( s ) ;
  10. int max1 = 1 ;
  11. char rasp [300] ;
  12. int i = lung / 2 ;
  13. char aux [300] , aux2[300] ;
  14. for ( i = 0 ; i <= lung - 2 ; ++i )
  15. {
  16. for ( int j = 2 ; j <= lung - j ; ++j )
  17. {
  18. strncpy( aux ,s + i , j ) ;
  19. aux[j] = NULL ;
  20. for ( int k = i + j ; k <= lung - j ; ++k )
  21. {
  22. strncpy( aux2 , s + k , j );
  23. aux2[j]= NULL ;
  24. if ( strcmp( aux , aux2 ) == 0 )
  25. {
  26. if ( j > max1 )
  27. {
  28. max1 = j ;
  29. strcpy( rasp , aux ) ;
  30. }
  31. else
  32. {
  33. if ( j == max1 )
  34. {
  35. if ( strcmp( aux , rasp ) < 0 ) strcpy( rasp , aux) ;
  36. }
  37. }
  38. break ;
  39. }
  40. }
  41. }
  42. }
  43. cout << rasp ;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement