1019 General Palindromic Number (20)(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 a~i~ as the sum of (a~i~b^i^) for i from 0 to k. Here, as usual, 0 <= a~i~ < b for all i and a~k~ is non-zero. Then N is palindromic if and only if a~i~ = a~k-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 <= 10^9^ is the decimal number and 2 <= b <= 10^9^ 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 "a~k~ a~k-1~ ... a~0~". 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

//题目大意是说:给出来一个数和数的基数d,并且判断在这个数在d进制下是否是回文数字。真的可以说是非常简单了。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector> using namespace std;
vector<long> v;
int main()
{
long n,d,t;
scanf("%lld%lld",&n,&d);
if(n==){
printf("Yes\n0");
return ;
}
while(n!=){
t=n%d;
n=n/d;
v.push_back(t);
}
t=v.size();
bool flag=true;
for(int i=;i<t/;i++){
if(v[i]!=v[t-i-]){
flag=false;break;
}
} if(flag)printf("Yes\n");
else printf("No\n");
printf("%lld",v[t-]);//倒序输出
for(int i=t-;i>=;i--)
printf(" %lld",v[i]);
return ;
}

//但是我还是提交错了,因为N输入可能是0,我没有考虑到这个特殊情况special case。。。。每次提交之后很多种情况都是发现这个出问题了。

PAT 1019 General Palindromic Number[简单]的更多相关文章

  1. PAT 1019 General Palindromic Number

    1019 General Palindromic Number (20 分)   A number that will be the same when it is written forwards ...

  2. PAT 甲级 1019 General Palindromic Number(简单题)

    1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...

  3. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  4. PAT 甲级 1019 General Palindromic Number(20)(测试点分析)

    1019 General Palindromic Number(20 分) A number that will be the same when it is written forwards or ...

  5. PAT 甲级 1019 General Palindromic Number (进制转换,vector运用,一开始2个测试点没过)

    1019 General Palindromic Number (20 分)   A number that will be the same when it is written forwards ...

  6. 1019 General Palindromic Number (20 分)

    1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards or ...

  7. 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 ...

  8. PTA (Advanced Level) 1019 General Palindromic Number

    General Palindromic Number A number that will be the same when it is written forwards or backwards i ...

  9. PAT 甲级 1019 General Palindromic Number

    https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 A number that will be ...

随机推荐

  1. boost::noncopyable介绍

    http://blog.csdn.net/huang_xw/article/details/8248960# boost::noncopyable比较简单, 主要用于单例的情况.通常情况下, 要写一个 ...

  2. 【cs229-Lecture10】特征选择

    本节课要点: VC维: 模型选择算法 特征选择 vc维:个人还是不太理解.个人的感觉就是为核函数做理论依据,低维线性不可分时,映射到高维就可分,那么映射到多高呢?我把可分理解为“打散”. 参考的资料: ...

  3. Elasticsearch学习之深入搜索三 --- best fields策略

    1. 为帖子数据增加content字段 POST /forum/article/_bulk { "} } { "doc" : {"content" : ...

  4. Artech的MVC4框架学习——第七章Action的执行

    概况:Action的执行不仅包含action方法的执行,还包含相关筛选器的执行. 第一基于线程池的请求,http请求称谓工作线程(p321),基于线程池优势:工作线程重用和工作线程数量的限制. 第二两 ...

  5. 记录一下使用Ubuntu16.0.4配置和使用docker registry

    h1, h2, h3, h4, h5, h6, p, blockquote { margin: 5px; padding: 5; } body { font-family: "Helveti ...

  6. VS2003安装Opencv1.0 windows系统 win7

    一.步骤 下载安装opencv1.0     安装文件我上传到百度网盘分享连接 http://pan.baidu.com/s/1o8na0aA 配置电脑windows环境变量 配置VS2003全局设置 ...

  7. ASP.NET Cookie概念、CURD操作、原理、实际运用

    会话就WEB开发来说,一个会话就是你通过浏览器与服务器之间的一次通话,只不过这种通话是以用浏览器浏览的方式来实现的. 就会话的应用来说,一般会话是用来识别用户的,比如你可以使用会话级变量记录当前用户已 ...

  8. javap(反汇编命令)详解

    javap是JDK自带的反汇编器,可以查看java编译器为我们生成的字节码.通过它,我们可以对照源代码和字节码,从而了解很多编译器内部的工作. 语法: javap [ 命令选项 ] class. . ...

  9. Unity3D笔记 切水果三 切水果

    一.创建一个Apple00,拖拽Prfabs下的Sprite命名为Apple00,添加碰撞器Box Collider,编写代码Knife Rey1.js 二.做被切的苹果 步骤和一是一样的,但是被切的 ...

  10. REM+SVG Sprite,web app案例

    REM+SVG Sprite,构建新时代web app <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN&quo ...