1023. Have Fun with Numbers (20)

400 ms

65536 kB

16000 B

Standard

CHEN, Yue

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:
1234567899

Sample Output:
Yes
2469135798

用数组表示，进行加法
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;
int a[25];
int c[25];
char b[25];
int tag[10];
int len;
{
int i=0;
int num=0;
while(i<len||num!=0)
{
a[i]+=(a[i]+num);
num=a[i]/10;
a[i]%=10;
i++;
}
return i;
}
int main()
{
scanf("%s",b);
len=strlen(b);
memset(tag,0,sizeof(tag));
memset(a,0,sizeof(a));
for(int i=0;i<len;i++)
{
a[len-1-i]=b[i]-'0';
tag[b[i]-'0']++;
}

for(int i=0;i<cnt;i++)
{
tag[a[i]]--;
}
bool ans=true;
for(int i=0;i<=9;i++)
{
if(tag[i]!=0)
ans=false;
}
if(!ans)
printf("No\n");
else
printf("Yes\n");
for(int i=cnt-1;i>=0;i--)
printf("%d",a[i]);
printf("\n");

return 0;
}

PAT 1023. Have Fun with Numbers (20)

2014-08-26 01:44:52

1023.Have Fun with Numbers (20)

2017-01-26 19:55:32

PAT: 1023. Have Fun with Numbers (20)

2014-03-23 21:17:52

自测4. Have Fun with Numbers (20)

2015-05-31 12:11:01

PAT Have fun with numbers (Python)

2015-06-29 00:57:25

自测题IV——Have Fun with Numbers (20)

2015-04-26 15:11:09

1023. Have Fun with Numbers (20)【字符串操作】——PAT (Advanced Level) Practise

2015-12-01 23:45:33

PAT甲级1008（Java）

2016-08-25 18:11:41

牛客网 PAT（甲级） 1012 Kuchiguse (20)

2017-06-15 14:14:15

PAT_自测4_Have Fun with Numbers

2016-11-25 15:06:02