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
");
        printf("0
");
    }
    else
    {
        tot=0;
        while(n) s[tot++]=n%b,n=n/b;
        if(check()) printf("Yes
");
        else printf("No
");
        for(int i=tot-1; i>=0; i--)
        {
            printf("%d",s[i]);
            if(i>0) printf(" ");
            else printf("
");
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zufezzt/p/5499348.html