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;
}
时间: 2024-08-25 09:31:49

PAT (Advanced Level) 1019. General Palindromic Number (20)的相关文章

PAT Advanced 1019 General Palindromic Number (20分)

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Although palindromic numbers are most often cons

1019. General Palindromic Number (20)

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Although palindromic numbers are most often cons

1019 General Palindromic Number (20)(20 point(s))

problem A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Although palindromic numbers are most of

PAT:1019. General Palindromic Number (20) AC

#include<stdio.h> #include<stdlib.h> int main() { int n,jin; scanf("%d%d",&n,&jin); if(0==n) //特判0的时候,就是回文数 { printf("Yes\n0"); return 0; } int arr[50],i=0; while(n!=0) { arr[i++]=n%jin; n/=jin; } int tag=0; for(int

PAT甲题题解-1019. General Palindromic Number (20)-又是水题一枚

n转化为b进制的格式,问你该格式是否为回文数字(即正着写和倒着写一样)输出Yes或者No并且输出该格式又是水题... #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int maxn=30; int a[maxn]; int n,b; int main() { scanf("%d %d&q

PAT 1019 General Palindromic Number[简单]

1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Altho

PAT 甲级 1019 General Palindromic Number (进制转换,vector运用,一开始2个测试点没过)

1019 General Palindromic Number (20 分)   A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Althoug

pat1019. General Palindromic Number (20)

1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic

PAT 甲级 1019 General Palindromic Number

https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit num