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 file 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:1234567899Sample Output:
Yes 2469135798
#include<stdio.h>
#define LEN 20
int main()
{
int i=0;
int j=0;
int array[10]={0};
usigned long long num1,num2,num3,num4;
scanf("%llu",&num1);
num4=num1;
num2=num1*2;
num3=num2;
while(num1){
array[num1%10]++;
num1=num1/10;
}
while(num2)
{
array[num2%10]--;
num2=num2/10;
}
int flag=1;
for(i=0;i<=9;i++)
{
if(array[i]!=0){
flag=0;
break;
}
}
if(flag==1)
printf("Yes\n");
else
printf("No\n");
printf("%llu",num3);
//printf("%llu",num4);
}
这段代码的结果是部分正确,因为usigned long long 最大值为2^64=18446744073709551616
预算20位数时会溢出,找不到更大的数据类型来存储所以不能偷懒了,换数组存储。
本文探讨了一种独特的数字属性:当某个特定的9位数(由1至9组成且不重复)翻倍后,其结果仍是由这些数字重新排列组成的9位数。通过输入任意不超过20位的正整数,程序将判断该数翻倍后是否依然保持这种数字排列的特性,并输出判断结果及翻倍后的数值。

被折叠的 条评论
为什么被折叠?



