题目链接:点击打开链接
知识点笔记:
对一个P进制数x转换为Q进制,需要两步
Step1:将P进制x转换为十进制数y
int y=0,product=1;
while(x!=0){
y = y + (x%10)*product;
x /= 10;
product *= P;
}
Step2:将十进制数y转换为Q进制数z
int z[40],num=0;
do{
z[num++] = y%Q;
y/=Q
}while(y!=0);
AC代码:
#include <iostream>
using namespace std;
bool Judge(int z[],int num){
for(int i=0;i<=num/2;i++){
if(z[i]!=z[num-1-i])
return false;
}
return true;
}
int main() {
int x,p;
scanf("%d %d",&x,&p);
int y[40],num=0;
do{
y[num++] = x%p;
x/=p;
}while(x!=0);
bool flag = Judge(y,num);
if(flag==true) printf("Yes\n");
else printf("No\n");
for(int i=num-1;i>=0;i--){
printf("%d",y[i]);
if(i!=0) printf(" ");
}
return 0;
}