首页 > 其他 > 详细

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

时间:2016-05-16 21:37:16      阅读:124      评论:0      收藏:0      [点我收藏+]

简单题。

#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;
}

 

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

原文:http://www.cnblogs.com/zufezzt/p/5499348.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!