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 15:03:59 浏览: 23
首先,我们需要将输入的数转换成字符串,并计算出它的长度。接着,我们将该数乘以2,再将结果转换成字符串,并且将它的长度与原始字符串的长度进行比较。如果长度不同,那么乘以2得到的数字肯定不是原始数字的排列。如果长度相同,那么我们需要逐一检查乘以2得到的数字中的每一个数字,确保它们在原始数字中都存在且出现的次数相同。如果满足这个条件,那么乘以2得到的数字就是原始数字的排列,否则就不是。
下面是实现这个算法的代码:
相关问题
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.
注意,数字123456789是一个由数字1到9组成的9位数,没有重复。将它翻倍,我们将得到246913578,这恰好是另一个由数字1到9组成的9位数,只是排列不同。现在你应该检查如果我们再次将其翻倍的结果是什么!现在你应该检查是否还有更多具有此属性的数字。也就是说,将一个有k位数字翻倍,你需要判断结果数字是否只由原始数字的排列组成。
notice that the number 123456789 is a 9-digit number consisting exactly the
数字123456789是一个9位数,正好是由1到9这9个数字组成的。这种数字被称为“连续数”或“全数字数”。它是一个“1到9全数字数”,意思是它包含了1到9这些数字,并且每个数字都只出现了一次。
这种类型的数字在数学中是很有趣的,因为它们在很多数学问题中都有特殊的性质。例如,它们可以被用来构建其他特殊的数字,或者用来解决一些数字逻辑问题。
在这个特定的例子中,我们可以看到123456789这个数字正好包含了1到9这些连续的数字,而且每个数字都只出现了一次。这种数字在数学游戏、数独等解密游戏中经常被使用,因为它们具有独特的特性。
总之,123456789这个9位数的特殊之处在于它是由1到9这些数字恰好组成的,没有多余的数字,也没有缺少的数字。这种数字给人一种整齐、有序的感觉,同时也展现了数字之间的特殊的关联。