Python实现Pat 1023. Have Fun with Numbers (20)

ゞ 浴缸里的玫瑰 2022-06-04 08:07 310阅读 0赞

题目

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.

Input Specification:

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

Output Specification:

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.

Sample Input:
1234567899
Sample Output:
Yes
2469135798

解答

  1. s1=input()
  2. num1=int(s1)
  3. num2=num1*2
  4. s2=str(num2)
  5. li1 = list(s1)
  6. li2 = list(s2)
  7. li1.sort()
  8. li2.sort()
  9. if li1==li2:
  10. print ('Yes')
  11. else:
  12. print('No')
  13. print(num2)

这里写图片描述

发表评论

表情:
评论列表 (有 0 条评论,310人围观)

还没有评论,来说两句吧...

相关阅读

    相关 PAT-B 1023. 组个最小数 (20)

    给定数字0-9各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意0不能做首位)。例如:给定两个0,两个1,三个5,一个8,我们得到的最