-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy path1023_Have Fun with Numbers (20).cpp
69 lines (67 loc) · 1.42 KB
/
1023_Have Fun with Numbers (20).cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int i;
char val[25];
while(cin >> val)
{
string A = "";
int len = strlen(val);
for(i = 0; i < len; i++)
A += val[i];
for(i = 0; i < len/2; i++)
{
char tmp = val[i];
val[i] = val[len-i-1];
val[len-i-1] = tmp;
}
for(i = len; i < 25; i++)
{
val[i] = '0';
}
int carry = 0;
for(i = 0; i < len; i++)
{
int tmp = (val[i]-'0')*2 + carry;
val[i] = tmp % 10 + '0';
carry = tmp / 10;
}
if(carry)
{
val[i] = ((val[i]-'0')*2 + carry) % 10 + '0';
i++;
}
len = i;
string B = "";
for(i = len-1; i >= 0; i--)
{
B += val[i];
}
if(A != B)
{
string tmp = B;
sort(A.begin(), A.end());
sort(B.begin(), B.end());
if(A == B)
{
cout << "Yes" << endl;
cout << tmp << endl;
}
else
{
cout << "No" << endl;
cout << tmp << endl;
}
}
else
{
cout << "No" << endl;
cout << B << endl;
}
}
return 0;
}