Day48: [PAT甲级] 1023 Have Fun with Numbers (20分)
题源:
来自PAT真题库:
https://pintia.cn/problem-sets/994805342720868352/problems/994805478658260992
代码:
dirty code凑合看吧
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<set>
#include<unordered_set>
#include<cstdio>
#include<algorithm>
using namespace std;
string s,res;
int main() {
cin >> s;
unordered_set<char> se1, se2;
int jinwei = 0;
for (int i=s.size()-1;i>=0;i--) {
se1.insert(s[i]);
int x = (s[i] - '0') * 2+jinwei;
if (x >= 10) {
jinwei = 1;
x -= 10;
}
else jinwei = 0;
res.append(1, '0' + x);
se2.insert('0'+x);
}
if (jinwei != 0) {
res.append(1, '0' + jinwei);
se2.insert('0' + jinwei);
}
reverse(res.begin(), res.end());
if (se1 == se2) cout << "Yes" << endl;
else cout << "No" << endl;
cout << res << endl;
system("pause");
}