zoukankan      html  css  js  c++  java
  • 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
    ",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
    ");
        else
            printf("No
    ");
        printf("%d",a[cnt-1]);
        for(int i=cnt-2;i>=0;i--){
            printf(" %d",a[i]);
        }
        printf("
    ");
        return 0;
    }
    View Code
  • 相关阅读:
    灌注和宝石性道法价比分析
    bzoj1912
    bzoj3504
    poj3580
    bzoj1251
    bzoj3223
    bzoj1212
    bzoj3790
    记一次惨痛的比赛
    bzoj2734
  • 原文地址:https://www.cnblogs.com/chenxiwenruo/p/6728057.html
Copyright © 2011-2022 走看看