Advertisement
Guest User

Untitled

a guest
May 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. string s,z,p;
  10. getline(cin,s);
  11. string x=s.substr(0,4);
  12. int br=0,max=0;
  13. for(int i=0; i<s.size()-3; i++)
  14. {
  15. z=s.substr(i,4);
  16. for(int j=i+1; j<s.size()-3; j++)
  17. {
  18. p=s.substr(j,4);
  19. if(p==z){br++;}
  20. }
  21. if(br>max){x=z;max=br;}
  22. if(br == max && strcmp(x.c_str(), z.c_str()) > 0){ // strcmp(x.c_str(), z.c_str()) > 0 -> x leks. kraci od z; strcmp(x.c_str(), z.c_str()) < 0 -> x leks. duzi od z; strcmp(x.c_str(), z.c_str()) == 0 -> z i x su isti
  23. x = z;
  24. max = br;
  25. }
  26. br=0;
  27. }
  28. cout<<x;
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement