# Include <iostream> # include <string> using namespace STD; /* calculate the minimum Lexicographic Order of string s in the minimum notation and return the first letter position of the string with the smallest Lexicographic Order */INT minstr (char s []) {int Len = strlen (s ); int I = 0, j = 1; while (I <= len-1 & J <= len-1) {int K = 0; while (k <= len-1 & S [(I + k) % Len] = s [(j + k) % Len]) K ++; if (k> = Len) break; If (s [(I + k) % Len]> S [(j + k) % Len]) I = max (I + k + 1, J + 1 ); /// at this time, s [I + 1] to s [I + k] cannot start with the minimum string, in addition, s [I + 1] to s [J] cannot start with the minimum string (the string starting with s [I] is compared with the string starting with s [J, it has already been noted that the string starting with s [I] is smaller than the string starting with s [I + 1] to starting with s [J-1) else J = max (J + k + 1, I + 1); // same as above} return min (I, j );} /* returns the first letter position of the string with the largest Lexicographic Order */INT maxstr (char s []) {int Len = strlen (s ); int I = 0, j = 1; while (I <= len-1 & J <= len-1) {int K = 0; while (k <= len-1 & S [(I + k) % Len] = s [(j + k) % Len]) K ++; if (k> = Len) break; If (s [(I + k) % Len] <s [(j + k) % Len]) I = max (I + k + 1, J + 1); else J = max (J + k + 1, I + 1);} return min (I, j);} int main () {return 0 ;}
Maximum and minimum string representation Template