Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 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. if ( strstr ( s + i + j , aux ) )
  21. {
  22. if ( j > max1 )
  23. {
  24. max1 = j ;
  25. strcpy ( rasp , aux );
  26. }
  27. else
  28. {
  29. if ( j == max1 )
  30. {
  31. if ( strcmp ( aux , rasp ) < 0 ) strcpy( rasp , aux ) ;
  32. }
  33. }
  34. }
  35. }
  36. }
  37. cout << rasp ;
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement