http://pat.zju.edu.cn/contests/pat-practise/1024
1 #include <stdio.h> 2 #include <stack> 3 using namespace std; 4 int main() 5 { 6 int N,b; 7 scanf("%d%d",&N,&b); 8 if(N==0) { 9 printf("Yes\n"); 10 printf("0\n"); 11 return 0; 12 } 13 14 stack<int> S; 15 int temp=N; 16 int tran=0; 17 while(N) { 18 S.push(N%b); 19 tran=tran*b+(N%b); 20 N/=b; 21 } 22 if(tran==temp) { 23 printf("Yes\n"); 24 } else { 25 printf("No\n"); 26 } 27 while(S.size()!=1) { 28 printf("%d ",S.top()); 29 S.pop(); 30 } 31 printf("%d\n",S.top()); 32 S.pop(); 33 }