链接:http://www.patest.cn/contests/pat-a-practise/1019
本来想用char数组存每一位的数字节省空间,但是因为进制>10,所以比较麻烦,改用int就可以
#include<cstdio>
#include<cstring>
#include<cstring>
#include<iostream>
using namespace std;
int num[90000000];
int main()
{
int a,b;
cin>>a>>b;
int tot=0;
if(a==0)
{
cout<<"Yes"<<endl<<0<<endl;
return 0;
}
while(a)
{
num[tot++]=a%b;
a/=b;
}
bool flag=true;
for(int i=0,j=tot-1; i<j; i++,j--)
{
if(num[i]!=num[j])
{
flag=!flag;
break;
}
}
if(flag)
cout<<"Yes"<<endl;
else cout<<"No"<<endl;
for(int i=tot-1; i>=0; i--)
{
if(i>0)
cout<<num[i]<<" ";
else
cout<<num[i]<<endl;
}
return 0;
}