PTA 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.
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 此题做时,需要特别注意数据类型,由于其数据要求不超过20位,也就是最多可能是20个9组成的一个大数据。此数据用long ulong double 都有些问题,最后只能将输入的数据设置为decimal型,才运行正常。 另外此题要求的是输入的数据*2后还是原来的所有数字组成,每个数字出现的次数也必须一样,不能多,不能少,只能是排列有些区别,一定要注意这一条。 于是小子将原来的输入数据的数字和数字出现的次数记录进了一个dictionary;然后将输入数据*2后的数字,一个个取出,dictionary中若不存在,那么肯定不是了;存在就将数字的次数-1;最后遍历一下dictionary中的所有次数是不是都为0,这是小子的笨方法。看了下,运行时间40ms左右。