Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cstring>
- #define N 100001
- using namespace std;
- ifstream fin("minlex.in");
- ofstream fout("minlex.out");
- char s[N];
- int n;
- bool comparare(char s[], int i , int j)
- {
- int k;
- for(k=0;k<n;k++)
- {
- if(s[i]<s[j]) return 0;
- if(s[i]>s[j]) return 1;
- i=(i+1)%n;
- j=(j+1)%n;
- }
- return 1;
- }
- int minlex(char s[])
- {
- int poz=0;
- for(int i=1;i<n;i++)
- if(comparare(s,poz,i))
- poz=i;
- return poz;
- }
- int main()
- {
- fin>>s;
- n=strlen(s);
- fout<<minlex(s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement