-
Notifications
You must be signed in to change notification settings - Fork 0
/
1023.cpp
51 lines (49 loc) · 1.02 KB
/
1023.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
#include <iostream>
using namespace std;
int main(){
string s;
cin >> s;
int addition = 0;
string ans = ""; //倒序存储结果
for (int i=s.size()-1; i>=0; i--){
int temp = (s[i] - 48) * 2 + addition;
if (temp >= 10){
addition = 1;
temp -= 10;
}
else {
addition = 0;
}
ans += (temp + 48);
}
bool found = false;
if (addition > 0){
ans += '1';
}
else{
for (int i=0; i<ans.size(); i++){
found = false;
for (int j=0; j<s.size(); j++){
if (ans[i] == s[j]){
s[j] = '*';
found = true;
break;
}
}
if (!found){
break;
}
}
}
if (found){
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
for (int i=ans.size()-1; i>=0; i--){
cout << ans[i];
}
cout << endl;
return 0;
}