Sample Input:
1234567899
Sample Output:
Yes
2469135798
思路: 题意:输入一个长度不大于20的正整数,计算其双倍,先输出是否是原数字的改变排列,然后输出双倍结果。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
char a[22];
int b[22];
int c[22];
int e[10];
int k[10];
int main()
{
scanf("%s", a);
for (int i = strlen(a) - 1; i >= 0; --i)
{
b[strlen(a) - i] = a[i] - '0';
}
int f = 0;
for (int i = 1; i <= strlen(a); ++i)
{
c[i] += b[i] * 2;
c[i + 1] += c[i] / 10;
c[i] %= 10;
if (i == strlen(a) && c[i + 1] != 0)
{
f = 1;
}
}
for (int i = 1; i <= strlen(a); ++i)
{
e[b[i]]++;
}
for (int i = 1; i <= strlen(a) + f; ++i)
{
k[c[i]]++;
}
int flag = 0;
for (int i = 0; i <= 9; ++i)
if (e[i] != k[i])
{
flag = 1;
break;
}
if (flag)
printf("No\n");
else
printf("Yes\n");
for (int i = strlen(a) + f; i >= 1; --i)
printf("%d", c[i]);
return 0;
}