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;
}
View Code

相关文章:

  • 2021-06-30
  • 2021-12-09
  • 2021-04-17
  • 2022-12-23
  • 2021-07-05
  • 2021-07-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2021-08-01
  • 2021-08-26
  • 2022-12-23
  • 2021-06-29
相关资源
相似解决方案