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
考点是怎么处理特别大的数, 超过了unsigned long 的范围。题目要求是会输入不超过20位的整数,因为太大了只能通过字符串读入(注意,因为是字符串所以长度要比20大1位,来储存’\0‘)。
整体分为两部分,第一部分处理读入的数据,把字符转换成int复制给a数组,再把每一位数字乘以2,复制给b数组,再单独处理b数组进位。这样我们就得到了两个大数,a是原数字,b是乘以二之后的数字。第二部分是遍历两个数组,储存他们的数字出现的次数,再比对出现的次数,相同就是yes 不同就是no,特殊的一点是如果b数组的第一位是两位数,意味着b数组比a数组多一位,所以一定是no。
#include <stdio.h>
#include <string.h>
int main(void)
{
char bignumber[21