【1019】General Palindromic Number (20 分)

简介: 【1019】General Palindromic Number (20 分)【1019】General Palindromic Number (20 分)
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>  
#include<map>
#include<vector>
#include<queue> 
using namespace std;  
bool Judge(int z[],int num){ //判断数组z所存数是否为回文数,num为位数
  for(int i=0;i<=num/2;i++){
    if(z[i]!=z[num-1-i]){  //如果位置i与对称位置num-1-i不相同
      return false;
    }
  }
  return true;  //所有位置都对称
}
int main(){   
  int n,b,z[40] ,num=0;  //数组存放转换结果,num为其位数
  scanf("%d%d",&n,&b);
  do{  //将n转换为b进制,结果存在数组z中
    z[num++]=n%b; //除基取余
    n/=b;
  }while(n!=0);//当n变为0时退出循环
  bool flag=Judge(z,num); //判断数组z保存的数是否回文
  if(flag==true) printf("Yes\n");
  else printf("No\n");
  for(int i=num-1;i>=0;i--){  //注意输出数组是从后往前的!!!
    printf("%d",z[i]);
    if(i!=0) printf(" ");
  }
  system("pause");
    return 0;   
}
相关文章
完美解决Non-terminating decimal expansion; no exact representable decimal result.异常
完美解决Non-terminating decimal expansion; no exact representable decimal result.异常
17195 0
完美解决Non-terminating decimal expansion; no exact representable decimal result.异常
|
11月前
|
人工智能 文件存储 C++
【PAT甲级 - C++题解】1019 General Palindromic Number
【PAT甲级 - C++题解】1019 General Palindromic Number
55 0
|
算法
LeetCode 260. Single Number III
给定一个整数数组 nums,其中恰好有两个元素只出现一次,其余所有元素均出现两次。 找出只出现一次的那两个元素。
75 0
LeetCode 260. Single Number III
PAT (Advanced Level) Practice - 1082 Read Number in Chinese(25 分)
PAT (Advanced Level) Practice - 1082 Read Number in Chinese(25 分)
81 0
PAT (Advanced Level) Practice - 1053 Path of Equal Weight(30 分)
PAT (Advanced Level) Practice - 1053 Path of Equal Weight(30 分)
102 0
【1144】The Missing Number (20 分)
【1144】The Missing Number (20 分) 【1144】The Missing Number (20 分)
69 0
【1082】Read Number in Chinese (25 分)
【1082】Read Number in Chinese (25 分) 【1082】Read Number in Chinese (25 分)
93 0