1019. General Palindromic Number (20)

时间限制
400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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题解的更多相关文章

  1. 浙大pat1050题解

    1050. String Subtraction (20) 时间限制 10 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Given two string ...

  2. 浙大pat1020题解

    1020. Tree Traversals (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Suppo ...

  3. 浙大pat1013题解

    1013. Battle Over Cities (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...

  4. 浙大pat1009题解

    1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  5. 浙大pat1042题解

    1042. Shuffling Machine (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Shu ...

  6. 浙大pat 1011题解

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  7. 浙大PAT 7-06 题解

    #include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...

  8. 浙大pat 1012题解

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  9. 浙大 pat 1003 题解

    1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

随机推荐

  1. glib实践篇:父类与子类

    前言: 众所周知,C语言是一门面向过程的语言,但是不代表就得跟面向对象完全绝缘,在C语言库glib中有gobject那么一套面向对象的机制,基于C语言的面向对象设计便是基于该实现机制. 今天所要实践的 ...

  2. [SQL基础教程] 4-3 数据的更新(UPDATE)

    [SQL基础教程] C4 数据更新 4-3 数据的更新(UPDATE) UPDATE UPDATE <表名> SET <列名> = <表达式>; UPDATE &l ...

  3. hdu 3842 Machine Works(cdq分治维护凸壳)

    题目链接:hdu 3842 Machine Works 详细题解: HDU 3842 Machine Works cdq分治 斜率优化 细节比较多,好好体会一下. 在维护斜率的时候要考虑x1与x2是否 ...

  4. 深入理解Hadoop集群和网络

    导读:云计算和Hadoop中网络是讨论得相对比较少的领域.本文原文由Dell企业技术专家Brad Hedlund撰写,他曾在思科工作多年,专长是数据中心.云网络等.文章素材基于作者自己的研究.实验和C ...

  5. Oracle笔记(1) 简单查询、限定查询、数据的排序

    Oracle笔记(四) 简单查询.限定查询.数据的排序   一.简单查询 SQL(Structured Query Language) 结构化查询语言,是一种数据库查询和程序设计语言,用于存取数据以及 ...

  6. android studio 工程设置项

    1.在<工程根目录>\build\generated文件夹中 存在 xxx.jar 这个文件是用来做单元测试用的,但该功能目前还处于实验阶段,不想用可以关了. 去掉勾后,clean一下工程 ...

  7. web 服务器

    作为一个跨专业转行的我来说,对后台一团浆糊,最近在看php,学的进度比较慢 (1)ApacheApache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上.Apache ...

  8. 个性化推荐系统中的BadCase分析

    针对内测用户反馈,由于前一天点击了几个动画,导致第二天推荐的动画屏占比较高,于是开始对此badcase进行分析. 首先分析了该用户的历史观看纪录,由于系统升级,日志缺陷问题,导致该用户10.15-11 ...

  9. inux按照CPU、内存、磁盘IO、网络性能监测

    http://my.oschina.net/chape/blog/159640 系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长 ...

  10. 第一百一十八节,JavaScript,动态加载脚本和样式

    JavaScript,动态加载脚本和样式 一动态脚本 当网站需求变大,脚本的需求也逐步变大.我们就不得不引入太多的JS脚本而降低了整站的性能,所以就出现了动态脚本的概念,在适时的时候加载相应的脚本. ...