1496 普通回文数 PAT1019
作者:
NikoNairre
,
2023-11-19 16:04:16
,
所有人可见
,
阅读 89
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector<string> str;
vector<string> num_str(int n, int rdx)
{
if (n == 0) return vector<string>(1, "0");
vector<string> res;
while (n) {
int q = n / rdx;
res.push_back(to_string(n % rdx));
n = q;
}
return res;
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, b; cin >> n >> b;
vector<string> base = num_str(n, b);
int k = 0;
bool match = true;
for (int i = base.size() - 1; i >= 0; i-- ) {
if (base[i] != base[k]) {
match = false;
break;
}
k++ ;
}
if (match) cout << "Yes" << endl;
else cout << "No" << endl;
for (int i = base.size() - 1; i >= 0; i-- ) {
if (i != base.size() - 1) cout << " ";
cout << base[i];
}
return 0;
}