PAT甲级1019. General Palindromic Number (20)
来源:互联网 发布:网络视频传输方案 编辑:程序博客网 时间:2024/05/21 19:23
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
Given any non-negative 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 non-negative 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 “
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>using namespace std;#include <algorithm>/*进制转换,将每一位数字存入vector*/vector<int> getDigit(int num,int radix){ vector<int> D; while(num>0){ D.push_back(num%radix); num/=radix; } reverse(D.begin(),D.end()); return D;}/*判断是否为回文数。*/bool isPalindromic(vector<int>&D){ for(int i=0;i<=D.size()/2;i++){ if(D[i]!=D[D.size()-i-1]) return false; } return true;}int main(){ int num,radix; cin>>num>>radix; if(num==0) { cout<<"Yes"<<endl; cout<<"0"<<endl; } else{ vector<int> ans; ans=getDigit(num,radix); if(isPalindromic(ans)) cout<<"Yes"<<endl; else cout<<"No"<<endl; for(int i=0;i<ans.size()-1;i++) cout<<ans[i]<<" "; cout<<ans[ans.size()-1]; } return 0;}
- PAT甲级.1019. General Palindromic Number (20)
- 【PAT甲级】1019. General Palindromic Number (20)
- 1019. General Palindromic Number (20) PAT 甲级
- PAT甲级1019. General Palindromic Number (20)
- PAT甲级 1019. General Palindromic Number (20)
- PAT 甲级1019. General Palindromic Number (20)
- PAT 甲级 1019. General Palindromic Number (20)
- PAT 甲级 1019. General Palindromic Number
- [PAT-甲级]1019.General Palindromic Number
- PAT 甲级 1019. General Palindromic Number
- PAT(甲级)General Palindromic Number (20)
- 1019. General Palindromic Number (20)-PAT甲级真题
- 浙大PAT甲级1019. General Palindromic Number (20)
- PAT甲级练习1019. General Palindromic Number (20)
- PAT甲级真题及训练集(12)--1019. General Palindromic Number (20)
- 【PAT】1019. General Palindromic Number (20)
- 1019. General Palindromic Number (20)-PAT
- PAT 1019. General Palindromic Number (20)
- HDU1879 继续畅通工程
- ArrayList源码分析
- Unable to resolve target 'android-9'问题解决
- 公钥私钥
- js柯里化
- PAT甲级1019. General Palindromic Number (20)
- 章三习题1——UVA 1585
- Algorithm
- 安装两个Eclipse 版本不一致,高版本无法打开
- Eclipse如何安装GrepCode插件详细教程
- java关键字this的用法
- 阿里云服务器上搭建zookeeper的错误及解决
- 冒泡排序
- Android 7.0系统启动流程分析