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.
#include<stdio.h>
int length(long long a);
void bits(int a[],long long b);
void judgement(int a[],int b[],int len);
int main(){
int j,len;
long long num;
int numl[10];
for(j=0;j<10;j++){
numl[j] = 0;
}
scanf("%lld",&num);
len = length(num);
int arr[len];
bits(arr,num);
judgement(arr,numl,len);
num *=2;
len = length(num);
int arr_[len];
bits(arr_,num);
int rel = 1;
for(j=0;j<len;j++){
int n;
for(n=0;n<10;n++){
if(numl[n] == 0){
if(arr_[j] == n){
rel = 0;
}
}
}
}
if(rel){
printf("Yes\n");
printf("%lld",num);
}else{
printf("No\n");
printf("%lld",num);
}
return 0;
}
int length(long long a){
int cnt = 0;
for( ; ; ){
a /= 10;
cnt++;
if(a == 0)
break;
}
return cnt;
}
void bits(int a[],long long b){
int i = 0;
for(i=0; ;i++){
a[i] = b%10;
b /= 10;
if(b == 0)
break;
}
}
void judgement(int a[],int b[],int len){
int i = 0;
for(i=0;i<len;i++){
switch(a[i]){
case 0:
b[0] = 1;
break;
case 1:
b[1] = 1;
break;
case 2:
b[2] = 1;
break;
case 3:
b[3] = 1;
break;
case 4:
b[4] = 1;
break;
case 5:
b[5] = 1;
break;
case 6:
b[6] = 1;
break;
case 7:
b[7] = 1;
break;
case 8:
b[8] = 1;
break;
case 9:
b[9] = 1;
break;
}
}
}
超过unsigned long,输入中有数字不在结果中,但结果数字都在输入里
最长串,10个数字全出现
最长串全是9
这三种情况显示答案错误,目前自己没有找出来问题