pat

题目

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

#include <cstdio>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<char> vc;
vi record(10, 0), number;
int (){
string str;
cin >> str;
number.assign(str.size()+1, 0);
int i = str.size();
for(auto iter = str.rbegin(); iter != str.rend(); iter++){
int x = iter - '0';
record[x]++;
number[i--] += (x
2) % 10;

number[i] += (x * 2) / 10;
}
int start = (number[0] == 0) ? 1 : 0;
bool flag = true;
for(int i = start;i < number.size();i++)
record[number[i]]--;
for(int i = 0;i < 10;i++)
if(record[i] != 0)
flag = false;
if(flag)
printf("Yesn");
else
printf("Non");
for(int i = start;i < number.size();i++)
printf("%d", number[i]);
return 0;
}