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",&n,&b);
    int cnt=0;
    int tmp=n;
    if(tmp==0){
        cnt=1;
        a[0]=0;
    }
    while(tmp){
        a[cnt]=tmp%b;
//printf("cnt:%d a:%d\n",cnt,a[cnt]);
        cnt++;
        tmp=tmp/b;
    }
    bool flag=true;
    for(int i=0;i<=cnt/2;i++){
        if(a[i]!=a[cnt-1-i]){
            flag=false;
            break;
        }
    }

    if(flag)
        printf("Yes\n");
    else
        printf("No\n");
    printf("%d",a[cnt-1]);
    for(int i=cnt-2;i>=0;i--){
        printf(" %d",a[i]);
    }
    printf("\n");
    return 0;
}

时间: 2024-10-12 08:04:40

PAT甲题题解-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 (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

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[简单]

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