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. expressJS - 准备活动

    安装 nodeJS 1. package.json 2. CommonJS, AMD, ES6 3. Babel

  2. perl's Favorite Default: $_

    If you omit the control varibele from the beiginning of foreach loop, Perl uses its favrorite defaul ...

  3. 解决IE浏览器“无法显示此网页”的问题

    诊断后提示:远程计算机或设备不接受连接 其他浏览器可以正常使用,QQ什么的也都正常,只有IE不能上网诊断提示:远程计算机或设备将不接受连接 ,网上找了好多方法都行不通.最后发现了这种方法,问题简单解决 ...

  4. 使用Stardict命令行版本sdcv

    sdcv命令的常用选项如下: -l:列出安装的词典 -u:指定查词所用的词典 在我的电脑上列出的词典有: Dictionary's name Word count Merrian Webster 10 ...

  5. IPython与notebook 安装

    基于 python2.7.13 32-bit版本安装 1.安装pyreadline https://pypi.python.org/pypi/pyreadline 下载对应的32位版本 2.用pip安 ...

  6. hdu1029

    #include<iostream>#include<string.h>using namespace std;int main(){ int n,i; int t; int ...

  7. git 克隆到本地linux目录的2种方式

    登录到gitlab查看2种不同的地址 ssh 类型 地址 git@inc.xxxx:shiwf/xxxAdmin.git http类型 地址 http://inc.xxxx:8000/shiwf/xx ...

  8. SpringMVC一路总结(一)(转)

    itRed You are never too old to set another goal or to dream a new dream. SpringMVC一路总结(一) SpringMVC听 ...

  9. 安装mysql的遇到的问题

    源:安装用的是mysql官网的binary包. 之前装mysql都是直接放到/usr/local,就想试试放到其他地方,然后..就悲剧了. 安装步骤没啥说的,官网上有.因为放置的位置不一样所以有些执行 ...

  10. wxWidgets显示视频

    wxWidgets中似乎没有专门用于显示视频的控件(虽然有wxWidgets本身的openGL控件wxGLCANVAS,但是我没有去试--) 按照这篇文章所讲的,从wxPanel继承出一个DrawPa ...