浙大pat1019题解
1019. General Palindromic Number (20)
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 the sum of (aibi) for i from 0 to k. 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 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 "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 "algorithm"
#include<sstream>
#include "string"
#include "cmath"
#include "vector"
using namespace std;
#define max 1000
void ReverseRadix(int n, int d,vector<int>&a)
{
int temp;
do
{
temp = n%d;
a.push_back(temp);
n /= d;
} while (n!=0);
}
bool Isdecimal(const vector<int>&a)
{
int n =(int) a.size();
for(int i=0;i<n;i++)
{
if(a[i]!=a[n-1-i])
return false;
}
return true;
}
void OutPut(vector<int>&a)
{
int n = a.size()-1;
for(int i=n;i>=0;i--)
{
if(i != 0)
printf("%d ",a[i]);
else
printf("%d\n",a[i]);
}
}
int main()
{
int num;
int radix;
vector<int>a;
cin >> num >> radix;
ReverseRadix(num,radix,a);
if(Isdecimal(a))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
OutPut(a);
return 0;
}
浙大pat1019题解的更多相关文章
- 浙大pat1050题解
1050. String Subtraction (20) 时间限制 10 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Given two string ...
- 浙大pat1020题解
1020. Tree Traversals (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...
- 浙大pat1013题解
1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...
- 浙大pat1009题解
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 浙大pat1042题解
1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shu ...
- 浙大pat 1011题解
With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...
- 浙大PAT 7-06 题解
#include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...
- 浙大pat 1012题解
1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 浙大 pat 1003 题解
1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...
随机推荐
- 深入理解Hadoop集群和网络
导读:云计算和Hadoop中网络是讨论得相对比较少的领域.本文原文由Dell企业技术专家Brad Hedlund撰写,他曾在思科工作多年,专长是数据中心.云网络等.文章素材基于作者自己的研究.实验和C ...
- BGP服务器您了解多少?
BGP服务器是主要用在不同的自治系统(AS)之间交换路由信息,它的最主要功能在于控制路由的传播和选择最好的路由.比如,中国网通.中国电信.中国铁通和一些大的民营IDC运营商都具有AS号,全国各大网络运 ...
- spring boot maven 插件
spirng boot 需要使用专用maven插件打包,才能打包.引入如下. <build> <plugins> <plugin> ...
- 命令行启动Hololens Emulator,可解决内存不足的问题
有时候在虚拟机测试时常会出现 内存不足 的情况,导致应用卡顿,调整 /memsize 参数大小: start "HoloLens" "C:\Program Files ( ...
- ios开发之滑动长图截全屏应用
最近做项目遇到要求截取图片长度超出手机屏幕,即可滑动的长图截屏,这里简单说一下解决思路,下面附带Demo下载地址. ,当我们要截全屏时,将滑动视图的frame以及偏移量记录下来,然后将滑动视图偏移量设 ...
- CentOS6.5 部署VPN管理系统(StrongSwan+iKEv2+Freeradiu+Mysql+Daloradius)
一.环境介绍 Server IP:192.168.30.133 System: CentOS 6.5 Client:Winodows 二.编译安装StrongSwan 1.下载StrongSwan w ...
- 【Python】使用super初始化超类
初始化超类的传统方式,在子类的实例中调用超类的__init__()方法. 但是传统的方法有两个问题,比如: 问题1: class MyBaseClass: def __init__(self, val ...
- MYSQL的一些函数
原文地址:http://blog.sina.com.cn/s/blog_52d20fbf0100ofd5.html 1,字符串类的函数 CHARSET(str) //返回字串字符集CONCAT (st ...
- Python基础知识学习_Day3
一.字典用法 字典是一种key-value数据类型,通过key获取具体value的内容,字典的特性是无序.去重. 增删改查用法如下: 1.1基本增删改查操作 name = {"," ...
- @classmethod及@staticmethod方法浅析【python】
目前对于python中@classmethod 类方法和@staticmethod静态方法的有了一定的认识,之后有进一步的认识后继续记录. @classmethod :是和一个class类相关的方法, ...