Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstring>
- using namespace std;
- int main()
- {
- string s,z,p;
- getline(cin,s);
- string x=s.substr(0,4);
- int br=0,max=0;
- for(int i=0; i<s.size()-3; i++)
- {
- z=s.substr(i,4);
- for(int j=i+1; j<s.size()-3; j++)
- {
- p=s.substr(j,4);
- if(p==z){br++;}
- }
- if(br>max){x=z;max=br;}
- 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
- x = z;
- max = br;
- }
- br=0;
- }
- cout<<x;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement