# 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. 组个最小数

1023. 组个最小数 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B ...

## PAT甲级1023

1023. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 St...

## 1023. Have Fun with Numbers (20)-PAT甲级真题（大整数运算）

1023. Have Fun with Numbers (20) Notice that the number 123456789 is a 9-digit number consisting ex...

python

## pat 1023. Have Fun with Numbers (20)

1023. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 ...

## PAT: 1023. Have Fun with Numbers (20)

PAT Have Fun with Numbers Notice that the number 123456789 is a 9-digit number consisting exactly...

## PAT 1023. Have Fun with Numbers (20)

Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit...

## PAT (Advanced Level) Practise 1023 Have Fun with Numbers (20)

1023. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 ...

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)