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

来源:互联网 发布:江苏语音网络系统注册 编辑:程序博客网 时间:2024/05/23 05:09

题目

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

解答

s1=input()num1=int(s1)num2=num1*2s2=str(num2)li1 = list(s1)li2 = list(s2)li1.sort()li2.sort()if li1==li2:    print ('Yes')else:    print('No')print(num2)

这里写图片描述