PAT 1023 Have Fun with Numbers python解法


1023 Have Fun with Numbers(20分)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 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つの数をあげて、もしそれが倍になった后の数の中で数字がもとの数と同じならば、Yesを出力して、さもなくばNoを出力して、(例えば123、倍になった后に246で、数字はまったく异なって、Noを出力すべきで、更に例えば234567891で、倍になった后に469135782で、すべて数の字の1-9で、Yesを出力すべきです)、そして次の行でこの数の倍になった后の结果を出力します.
问题解决の考え方:问题の意味によって、1つのとても简単な考えがあります:入力の数sの中で1つのリストl 1を入れて并べて、更にs倍の后のdも1つのリストl 2を入れて并べて并べて、このように操作した后に、l 1とl 2が等しいかどうかを判断するだけでいいので、等しいならYesを出力して、さもなくばNoを出力して、それからdを出力します.
s = input()
l1 = [i for i in s]
l1.sort()
d = str(int(s)*2)
l2 = [i for i in d]
l2.sort()
if l1 == l2:
    print('Yes')
    print(d)
else:
    print('No')
    print(d)