4.Have Fun with Numbers【數據結構—起步能力自測題】

題目:

  Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be 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 you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.

輸入格式:

  Each input contains one test case. Each case contains one positive integer with no more than 20 digits.

輸出格式:

  For each test case, first print in a line “Yes” if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or “No” if not. Then in the next line, print the doubled number.

輸入樣例:

1234567899

輸出樣例:

Yes
2469135798

【題目大意】:

  數字123456789是一個9位數的數字,完全由1到9的數字組成,沒有重複。把它翻倍,就得到246913578,它正好是另一個9位數的數字,恰好由1到9這兩個數字組成,只是排列方式不同。再翻一倍看看結果!
  要檢查是否有更多的數字具有這個性質。也就是說,將一個給定的數字乘以兩倍,得到的數字是否只包含原數字中數字的排列。

思路:

  

AC代碼:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章