AcWing 1500. 趣味数字
原题链接
简单
作者:
星恒
,
2025-01-10 12:23:21
,
所有人可见
,
阅读 3
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int d1[10], d2[10];
int main()
{
string A;
vector<int> a;
cin >> A;
for (int i = A.size() - 1; i >= 0; i -- ) {
a.push_back(A[i] - '0');
d1[A[i] - '0']++;
}
vector<int> b;
int t = 0;
for (int i = 0; i < a.size(); i ++ )
{
int s = a[i] + a[i] + t;
b.push_back(s % 10);
t = s / 10;
}
if (t) b.push_back(t);
for (int i = 0; i < b.size(); i++) {
d2[b[i]]++;
}
for (int i = 0; i < 10; i++) {
if (d1[i] != d2[i]) {
cout << "No" << endl;
for (int i = b.size() - 1; i >= 0; i -- ) cout << b[i];
return 0;
}
}
cout << "Yes" << endl;
for (int i = b.size() - 1; i >= 0; i -- ) cout << b[i];
return 0;
}