Advertisement
iasmina_sarac

Untitled

Nov 13th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4. int main()
  5. {
  6. char s[256], tmax[256], t[256];
  7. int n,l,lmax=0,ok=1,i;
  8. cin.getline(s,255);
  9. n=strlen(s);
  10. for(l=n/2;l>=2 && ok;l--)
  11. {
  12. for(i=0;i<n-2*l;i++)
  13. {
  14. strncpy(t,s+i,l);
  15. t[l]=0;
  16. if(strstr(s+i+l,t))
  17. {
  18. if(lmax==0)
  19. {
  20. lmax=l;
  21. strcpy(tmax,t);
  22. }
  23. else
  24. if(strcmp(t,tmax)<0)
  25. strcpy(tmax,t);
  26. }
  27. }
  28. }
  29. cout<<tmax;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement