# UVa 1584 Circular Sequence---water problem

Source: Internet
Author: User

UVa 1584

Title: Given an n-letter ring string, you can start from any position by reading n letters clockwise, the output of which is the smallest dictionary order results

The idea of solving a problem: first using modulo operation to achieve a given ring string and two initial position, compare the two dictionary order size function,

Then use a layer of loops, make n comparison, save the minimum dictionary sequence of the first letter position, and then use the output of the modulo operation can be

`/*UVa 1584 Circular Sequence---water problem*/#include<cstdio>#include<cstring>//The string s is annular, p Q is the starting position length is n, the p is judged to be less than QintLessConst Char* S,intPintq) {    intLen =strlen (s);  for(inti =0; i < Len; ++i) {        if(s[(p + i)% len] > s[(q + i)%Len]) {            return-1;//p > Q        }        Else if(s[(p + i)% len] < s[(q + i)%Len]) {            return 1;//Q < Q        }    }    return 0;//Equal}intMain () {Chars[ the]; intT; scanf ("%d", &t);  while(t--) {scanf ("%s", s); intAns =0; intLen =strlen (s); //equivalent to having n strings to compare and pick out the smallest dictionary order         for(inti =1; i < Len; ++i) {            if(Less (S, i, ans) = =1) {ans=i; }        }        //after looping the selection ans has saved the dictionary order the position of the first character of the smallest string         for(inti =0; i < Len; ++i) {printf ("%c", s[(ans + i)%Len]); } printf ("\ n"); }//While (t)    return 0;}`
View Code

UVa 1584 Circular Sequence---water problem

Related Keywords:

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.