00-Self Test 4. Has fun with Numbers (20)

Source: Internet
Author: User

Notice that number 123456789 are a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we'll obtain 246913578, which happens to being another 9-digit number consisting exactly the numbers from 1 to 9, Only in a different permutation. Check to see the result if we double it again!

Now is suppose to check if there is more numbers with the This property. That's, double a given number with k digits, if the resulting number consists of only a permutation of th e digits in the original number.

Input Specification:

Each input file contains the one test case. Each case contains one positive integers with no more than digits.

Output Specification:

For each test case, first print in a line "Yes" if doubling the input number gives a number this consists of only a Permut Ation of the digits in the original number, or "No" if not. Then on the next line, print the doubled number.

Sample Input:
1234567899
Sample Output:
Yes2469135798
1 ImportJava.io.BufferedReader;2 Importjava.io.IOException;3 ImportJava.io.InputStreamReader;4 5  Public class Number6 {7      Public Static voidMain (string[] args)throwsIOException8     {9BufferedReader buf=NewBufferedReader (NewInputStreamReader (system.in));TenString line=buf.readline (); One         Char[] sou=Line.tochararray (); A         Char[] dou; -         Booleanb=false; -         if(sou[0]-' 0 ' >=5) the         { -b=false; -dou=New Char[Sou.length+1]; -dou[0]= ' 1 '; +              for(inti=sou.length-1,jin=0;i>=0;i--) -             { +Dou[i+1]= (Char) (((sou[i]-' 0 ') * *)%10+ ' 0 ' +Jin); A                 if((sou[i]-' 0 ') *2+jin>=10) atJin=1; -                 Else -Jin=0; -                  -             } -         } in         Else -         { todou=New Char[sou.length]; +              for(inti=sou.length-1,jin=0;i>=0;i--) -             { the                  *Dou[i]= (Char) (((sou[i]-' 0 ') * *)%10+ ' 0 ' +Jin); $                 if((sou[i]-' 0 ') *2+jin>=10)Panax NotoginsengJin=1; -                 Else theJin=0; +                  A             } the              +             int[] t1=New int[10]; -              for(inti=0;i<sou.length;i++) $             { $t1[sou[i]-' 0 ']++; -             } -             int[] t2=New int[10]; the              for(inti=0;i<dou.length;i++) -             {Wuyit2[dou[i]-' 0 ']++; the             } -              for(inti=0;i<t1.length;i++) Wu             { -                 if(t1[i]!=T2[i]) About                 { $b=false; -                      Break; -                 } -b=true; A             } +         } the  -         if(b==true) $         { theSystem.out.println ("Yes"); the System.out.println (dou); the         } the         Else -         { inSystem.out.println ("No"); the System.out.println (dou); the         } About              the          the     } the}

00-Self Test 4. Has fun with Numbers (20)

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.