PAT甲级——1019 General Palindromic Number
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 considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system. Consider a number N>0 in base b≥2, where it is written in standard notation with k+1 digits ai as ∑i=0k(aibi). Here, as usual, 0≤ai<b for all i and ak is non-zero. Then N is palindromic if and only if ai=ak−i for all i. Zero is written 0 in any base and is also palindromic by definition.
Given any positive decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b.
Input Specification:
Each input file contains one test case. Each case consists of two positive numbers N and b, where 0<N≤109 is the decimal number and 2≤b≤109 is the base. The numbers are separated by a space.
Output Specification:
For each test case, first print in one line Yes if N is a palindromic number in base b, or No if not. Then in the next line, print N as the number in base b in the form "ak ak−1 ... a0". Notice that there must be no extra space at the end of output.
Sample Input 1:
27 2
Sample Output 1:
Yes
1 1 0 1 1
Sample Input 2:
121 5
Sample Output 2:
No
4 4 1
//General Palindromic Number
#include<stdio.h>
#include<vector>
using namespace std;
vector<int>V;
int main(void){
 int n, b;
 while (scanf("%d%d", &n, &b) != EOF){
  V.clear();
  if (n == 0){//如果是0的话,不论什么进制都是回文数字
   puts("Yes");
   printf("0\n");
   continue;
  }
  while (n){//用V来存储b进制下的各个位数
   V.push_back(n % b);
   n /= b;
  }
  bool result  = true;;
  for (int i = 0; i < V.size(); i++){
   if (V[i] != V[V.size() - i - 1]){
    result = false;//一有不等的,就不是回文
    break;
   }
  }
  if (result){
   puts("Yes");
  }
  else puts("No");
  for (int i = V.size() - 1; i >= 0; i --){
   if (i == V.size() - 1)printf("%d", V[i]);
   else printf(" %d", V[i]);
  }
  printf("\n");
 }
 return 0;
}
												
											PAT甲级——1019 General Palindromic Number的更多相关文章
- PAT 甲级 1019 General Palindromic Number(20)(测试点分析)
		
1019 General Palindromic Number(20 分) A number that will be the same when it is written forwards or ...
 - PAT 甲级 1019 General Palindromic Number(简单题)
		
1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...
 - PAT 甲级 1019 General Palindromic Number (进制转换,vector运用,一开始2个测试点没过)
		
1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards ...
 - PAT 甲级 1019 General Palindromic Number
		
https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 A number that will be ...
 - 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 Nu ...
 - PAT甲级——A1019 General Palindromic Number
		
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
 - PAT (Advanced Level) Practice 1019 General Palindromic Number  (20 分) 凌宸1642
		
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
 - PAT 1019 General Palindromic Number
		
1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards ...
 - PAT 1019 General Palindromic Number[简单]
		
1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...
 
随机推荐
- 用Python在00:00给微信好友发元旦祝福语
			
2019年的元旦即将来临,这里用Python撸一串简单的代码来实现定点给微信里的所有小伙伴发祝福语 环境说明 Python版本: 不限 第三方库: itchat, schedule 注:所有祝福语来源 ...
 - CentOS7使用firewalld的基本命令
			
转自:https://www.cnblogs.com/moxiaoan/p/5683743.html.Thanks for 莫小安 1.firewalld的基本使用 启动: systemctl ...
 - 题解P4201: [NOI2008]设计路线
			
发现给出了一棵树, 不是树的情况直接输出-1 考虑进行DP, 设f[i][0/1/2]为i的子树中选小于等于0/1/2条边修路的方案数, 不妨对于一个节点, 先考虑正好相等的情况, 假设当前扫到了一个 ...
 - AT1983 BBQ Hard 解题报告
			
题意 求\(\sum_{i=1}^{n} \sum_{j=i+1}^{n} \dbinom{a_i+a_j}{a_i+b_i+a_j+b_j}\) 解法 考虑\(\dbinom{a_i+a_j}{a_ ...
 - SpringMVC的配置文件说明
			
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
 - SHIDOU
			
1. arp i 指定网卡 a 查看arp表,显示主机名称和ip n 查看arp表,并且用ip显示而不是主机名称 2. 119 ~/M2/image-installer- ...
 - SSM框架和微服务构架和的联系与区别
			
spring和springMvc: 1. spring是一个一站式的轻量级的java开发框架,核心是控制反转(IOC)和面向切面(AOP),针对于开发的WEB层(springMvc).业务层(Ioc) ...
 - ArrayList扩容原理分析
			
1:代码解读和分析 1.1:构造方法分析 1: public ArrayList(int initialCapacity) { ) { this.elementData = new Object[in ...
 - selenium破解人人登陆验证码
			
from selenium import webdriverfrom PIL import Imagefrom chaojiying import Chaojiying_Clientimport ti ...
 - awk中传参方式
			
结合编辑数据文件的shell脚本学习awk传参方式,该脚本功能: a.取VIDEOUSR_11082017_0102_ONLINE_STASTIC.dat文件中第87个字段的低8位: b.将每行数据的 ...