题目链接
题目描述
看题目链接
个人想法:
- 题目有所暗示,不要用字符串判定,用数字。
代码:
// 一个数字 水仙花数字
#include<iostream>
using namespace std;
const int N = 1e4+10;
int len = 0;
int mark[N];
int main()
{
int x, radix;
string s;
cin >> x >> radix;
if(x == 0) {
cout << "Yes" << endl << "0";
return 0;
}
while(x) {
mark[len ++] = x % radix;
x /= radix;
}
bool flag = false;
for(int i = 0, j = len - 1; i <= j; i++, j--) {
if(mark[i] != mark[j]) flag = true;
}
if(flag) cout << "No" << endl;
else cout << "Yes" << endl;
for(int i = len - 1; i >= 0; i--)
i != 0 ? cout << mark[i] << " " : cout << mark[i];
return 0;
}