PAT (Advanced Level) 1019. General Palindromic Number (20)

简单题。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;

int s[10000],tot;
int n,b;

bool check()
{
    for(int i=0; i<=tot/2; i++)
    {
        if(s[i]!=s[tot-i-1]) return 0;
    }
    return 1;
}

int main()
{
    scanf("%d%d",&n,&b);
    if(n==0)
    {
        printf("Yes\n");
        printf("0\n");
    }
    else
    {
        tot=0;
        while(n) s[tot++]=n%b,n=n/b;
        if(check()) printf("Yes\n");
        else printf("No\n");
        for(int i=tot-1; i>=0; i--)
        {
            printf("%d",s[i]);
            if(i>0) printf(" ");
            else printf("\n");
        }
    }
    return 0;
}

 

posted @ 2016-05-16 20:21  Fighting_Heart  阅读(141)  评论(0编辑  收藏  举报