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 19 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
时间: 2023-12-29 14:03:59 浏览: 63
检测输入的字符是否为0-9的数字(测试)
首先,我们需要将输入的数转换成字符串,并计算出它的长度。接着,我们将该数乘以2,再将结果转换成字符串,并且将它的长度与原始字符串的长度进行比较。如果长度不同,那么乘以2得到的数字肯定不是原始数字的排列。如果长度相同,那么我们需要逐一检查乘以2得到的数字中的每一个数字,确保它们在原始数字中都存在且出现的次数相同。如果满足这个条件,那么乘以2得到的数字就是原始数字的排列,否则就不是。
下面是实现这个算法的代码:
阅读全文