Răspuns:
#include<bits/stdc++.h>
using namespace std;
ifstream in("minlex.in");
ofstream out("minlex.out");
int main()
{
char s[1000010],x[1000010];
int n=0;
in>>s;
unsigned a=strlen(s);
strcpy(x,s);
strncat(s,s,a);
for(int k=0;s[k+a+1];k++)
{
if(strncmp(x,s+k,a)>0)
{
strncpy(x,s+k,a);
n=k;
}
}
out<<n;
}
Explicație: