Maximum and minimum string representation Template

Source: Internet
Author: User
# 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.