vijos-p1024-Cabriec Waltz (c + + && simple Simulation)

Source: Internet
Author: User

P1024Cabriec Waltz Accepted Tags: simulation<textarea id="code" class="textbox" style=""></textarea>Describe

Cabriec is a mathematician who, in his study of numbers, found that any one is not a four-digit number with exactly the same number, if each of them is reordered, a larger number and a smaller number, then the larger number minus the smaller number, the difference is not enough four digits when the 0, and so on, It will eventually become a fixed number: 6174, which is the Cabriec constant.

Example: 4321-1234=3087
8730-378=8352
8532-2358=6174
7641-1467=6147
If the K-digits are handled as such, they do not become a number, but rather form loops between several numbers, called Cabriec waltzes. For example, for five-digit 54321:
54321-12345=41976
97641-14679=82962
98622-22689=75933
97533-33579=63954
96543-34569=61974
97641-14679=82962
We call the 82962 75933 63954 61974 A cyclic section, the Cabriec Waltz.

Format input Format

The file contains several lines, one for each of the starting integers for "Cabriec Waltz" (less than Maxlongint)

Output format

Each behavior corresponds to a circular section of integers, and the data is separated by a space.

Example 1 sample input 1[copy]
432154321
Sample output 1[Copy]
617482962 75933 63954 61974
Limit

Each test point 1s

Source

Xiaomengxian
The second Test question of the freshman



Bo Master decided not always in HDU water down! Return to Vijos (in fact, to change the place of water ...) But at least, Vijos's problem does have a head ache .... Today I spent a lot of time to understand the problem ... Inside the junior high school students oier too much ..... Brother to kneel ... ORZ!!!

Thank Talent123 predecessors for their ingenious algorithms! (that's what I see!) )

You see above is a second Test question ... College dogs are finished by high school students!


Note: The input data should also be considered, it may be a follow-up link!


#include <iostream> #include <cstdio> #include <cstring>using namespace std;double number,circle[    1000];int check_print (int i) <span style= "White-space:pre" ></span>//check for the occurrence of a cyclic section or a loop point {    Int J;    for (j=0;j<i;j++) {if (circle[j]==circle[i]) break;                                          } if (j==i) return 0;         else {for (; j<i;j++) {printf ("%.0LF", Circle[j]);        <span style= "White-space:pre" ></span>//Direct output Loop section} printf ("\ n");    return 1; }}double pow1 (int n) <span style= "White-space:pre" ></span>//array subscript is a couple of times {if (n==0) ret that returns 10    Urn 1; else return Pow1 (n-1) *10;} Double confuse (double number) <span style= "White-space:pre" ></span>//MAX minimum subtract form recursive {char ch[1    50];    int temp;    Double max=0,min=0;                             sprintf (CH, "%.0f", number); <span style= "White-spacE:pre "></span>//Initialize ch array int i,j;                for (I=0;i<strlen (CH), i++) {for (J=0;j<strlen (CH)-i-1;j++) if (ch[j]>ch[j+1]) {                TEMP=CH[J];                CH[J]=CH[J+1];            Ch[j+1]=temp;        }} for (I=0;i<strlen (CH); i++) {Max+=pow1 (i) * (ch[i]-' 0 ');    Min+=pow1 (strlen (CH)-i-1) * (ch[i]-' 0 ');    } return max-min;    }void Femain (double number) {int i=0; for (i=0;;        i++) {circle[i]=number;        if (Check_print (i) ==1) break;        else {number = confuse (number);        }}}int Main () {while (1) {if (scanf ("%lf", &number) ==-1) break;        else {femain (number); }} return 0;}


vijos-p1024-Cabriec Waltz (c + + && simple Simulation)

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.