Advertisement
nicuvlad76

Untitled

Nov 16th, 2020
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3. #define N 100001
  4. using namespace std;
  5. ifstream fin("minlex.in");
  6. ofstream fout("minlex.out");
  7. char s[N];
  8. int n;
  9.  
  10. bool comparare(char s[], int i , int j)
  11. {
  12.     int k;
  13.     for(k=0;k<n;k++)
  14.     {
  15.         if(s[i]<s[j]) return 0;
  16.         if(s[i]>s[j]) return 1;
  17.         i=(i+1)%n;
  18.         j=(j+1)%n;
  19.     }
  20.     return 1;
  21. }
  22.  
  23. int minlex(char s[])
  24. {
  25.     int poz=0;
  26.     for(int i=1;i<n;i++)
  27.         if(comparare(s,poz,i))
  28.             poz=i;
  29.     return poz;
  30. }
  31. int main()
  32. {
  33.     fin>>s;
  34.     n=strlen(s);
  35.     fout<<minlex(s);
  36.     return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement