|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
7-49 Have Fun with Numbers
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
翻译
注意,123456789是一个9位数字,完全由1到9之间的数字组成,没有重复。把它翻倍,我们会得到246913578,它恰好是另一个9位数,包含了从1到9的数字,只是排列不同。如果我们再次加倍,看看结果如何!现在你要检查是否有更多的数字具有这个性质。也就是说,用k位数字将一个给定的数字加倍,你要判断得出的数字是否只由原数字中数字的一个排列组成。
输入说明
每个输入包含一个测试用例。每个例子包含一个不超过20位的正整数。
输出说明
对于每个测试用例,如果将输入数字加倍,得到的数字只包含原始数字的一个排列,则首先打印一行“Yes”;如果不包含,则打印“No”。然后在下一行中,打印加倍的数字。
Sample Input:
1234567899
Sample Output:
Yes
2469135798
我的代码:
- #include<stdio.h>
- void sum(long long n,int *p);
- void sum(long long n,int *p)
- {
- int i = 20;
- while(n)
- {
- p[i] = n%10;
- n /= 10;
- i--;
- }
-
- }
- void PD(int *pn,int *pt);
- void PD(int *pn,int *pt)
- {
- int n,m;
-
- for(n = 0;n < 21; n++)
- {
- for(m = 0;m < 21; m++)
- {
- if(pt[n] == pn[m])
- {
- pt[n] = 100;
- pn[m] = 100;
-
- continue;
- }
- }
- }
- }
- void Print(int *p);
- void Print(int *p)
- {
- int t = 1;
- int n;
-
- for(n = 0;n < 21;n++)
- {
- if(t && p[n] == 0)
- continue;
- printf("%d",p[n]);
- t = 0;
-
- }
- printf("\n");
- }
- int main()
- {
- unsigned long long n,two_n;
- int pn[21] = {0};
- int pt[21] = {0};
- int i;
- scanf("%lld",&n);
- two_n = 2*n;
-
- sum(n,pn);
- sum(two_n,pt);
-
-
- int demo_pt[21];
- for(i = 0;i < 21;i++)
- {
- demo_pt[i] = pt[i];
- }
-
- PD(pn,demo_pt);
-
- // Print(pn);
- // Print(pt);
- // Print(demo_pt);
-
- for(i = 0;i < 21; i++)
- {
- if(demo_pt[i] != 100 && pn[i] != 100)
- {
- printf("No\n");
- Print(pt);
- return 0;
- }
- }
-
- printf("Yes\n");
- Print(pt);
- return 0;
- }
复制代码
提示错误:
|
|