PAT甲级——A1019 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 (. Here, as usual, 0 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 is the decimal number and 2 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
#include <iostream>
#include <vector>
using namespace std;
//此处11进制中的10就是10,而不是a
int main()
{
int N, b;
cin >> N >> b;
vector<int>v1, v2;
while (N)
{
v1.push_back(N%b);
N /= b;
}
v2.assign(v1.rbegin(), v1.rend());
if (v1 == v2)
cout << "Yes" << endl;
else
cout << "No" << endl;
if (v2.size() == )
cout << ;
else
{
cout << v2[];
for (int i = ; i < v2.size(); ++i)
cout << " " << v2[i];
}
cout << endl;
return ;
}
PAT甲级——A1019 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
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT 甲级 1019 General Palindromic Number
https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 A number that will be ...
- PAT A1019 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
[题目] https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 题目大意:给定一个N和b,求N在b ...
- 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 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 ...
随机推荐
- (一)PHP基础知识考察点
1,PHP引用变量的考察点: 概念:引用就是用不同的名字访问同一个变量内容. 定义方式: 使用&符号. PHP引用变量的工作原理 这里有个COW copy on write 用zval() ...
- VS2010-MFC(对话框:文件对话框)
转自:http://www.jizhuomi.com/software/173.html 一 文件对话框的分类 文件对话框分为打开文件对话框和保存文件对话框,相信大家在Windows系统中 ...
- Activity详解三 启动activity并返回结果 转载 https://www.cnblogs.com/androidWuYou/p/5886991.html
首先看演示: 1 简介 .如果想在Activity中得到新打开Activity 关闭后返回的数据,需要使用系统提供的startActivityForResult(Intent intent, int ...
- 第十九篇:Mysql两次Group by和ip转数字作比较的一次优化
业务场景:两张表,ipconfig_group表存了单位和 ip 起始段信息 visit_info表存储了访问次数,失败次数,访问流量,用户ip等信息 两张表的关系为: 一个部门下有若干ip段, ...
- Censored! POJ - 1625 AC自动机+大数DP
题意: 给出一n种字符的字典,有p个禁用的单词, 问能组成多少个不同的长度为m的合法字符串.(m<=50) 题解: 是不是个我们之前做的题目非常非常像,题意都一样. 直接将上次写的AC自动机+矩 ...
- webpack 简单笔记(一)
安装部分不介绍了 (一)第一个最简单的demo,单入口,单文件 目录结构: webapck.config.js中代码: 'use strict' const path = require('path' ...
- JSONObjectSample
package com.egeniuss.platform.basic; import java.util.ArrayList; import java.util.HashMap; import ja ...
- HDU3480 Division——四边形不等式或斜率优化
题目大意 将N个数分成M部分,使每部分的最大值与最小值平方差的和最小. 思路 首先肯定要将数列排序,每部分一定是取连续的一段,于是就有了方程 $\Large f(i,j)=min(f(i-1,k-1) ...
- linux的mysql权限错误导致看不到mysql数据库
1.首先停止mysql服务:service mysqld stop2.加参数启动mysql:/usr/bin/mysqld_safe --skip-grant-tables & 然后就可以无任 ...
- sectionStorage与localStorage更新缓存,以及更新layui的数据缓存
var aa = sessionStorage.getItem('datInfo');//获取缓存数据 name = aa.user; var names = '张三'; sessionStorage ...