1019. General Palindromic Number (20)
生词以及在文中意思
forward 向前地 backward 向后地 palindromic 回文的 base 基数(如十进制的10 和二进制的2) numeral system 数制 decimal system 十进制
notation 记法
这题并不是单纯的进制转换。而是要求输入n和b,将n转换为a0*b^0+a1*b^1+......+ak*b^k的和的形式。再对a0,a1,.....,ak进行判断回文串。
import java.util.ArrayList;
import java.util.Scanner; public class Main { public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
if(n==0) {
System.out.println("Yes");
System.out.print("0");
return;
}
ArrayList<String> l=new ArrayList<String>();
while(n!=0) {
l.add(Integer.toString(n%m));
n/=m;
}
boolean IsTrue=true;
for(int i=0;i<l.size()/2;i++) {
if(!(l.get(i).equals(l.get(l.size()-1-i)))) {
IsTrue=false;
break;
}
}
if(IsTrue) {
System.out.println("Yes"); }
else {
System.out.println("No");
}
System.out.print(l.get(l.size()-1));
for(int i=l.size()-2;i>=0;i--) {
System.out.print(" "+l.get(i));
}
} }
1019. General Palindromic Number (20)的更多相关文章
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- 1019 General Palindromic Number (20)(20 point(s))
problem A number that will be the same when it is written forwards or backwards is known as a Palind ...
- PAT Advanced 1019 General Palindromic Number (20 分)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) (进制转换,回文数)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- 1019 General Palindromic Number (20 分)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT (Advanced Level) 1019. General Palindromic Number (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲题题解-1019. General Palindromic Number (20)-又是水题一枚
n转化为b进制的格式,问你该格式是否为回文数字(即正着写和倒着写一样)输出Yes或者No并且输出该格式又是水题... #include <iostream> #include <cs ...
- 【PAT甲级】1019 General Palindromic Number (20 分)
题意: 输入两个正整数n和b(n<=1e9,2<=b<=1e9),分别表示数字的大小和进制大小,求在b进制下n是否是一个回文串,输出“Yes”or“No”,并将数字n在b进制下打印出 ...
- PAT 1019 General Palindromic Number[简单]
1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...
随机推荐
- Ubuntu16.04 使用sudo cat EOF 编辑文件,提示Permission denied错误的解决办法
一.执行命令报错 在Ubuntu16.04下,使用如下命令,修改hosts主机文件,居然提示权限错误: catty@node186:~$ sudo cat <<EOF > /etc/ ...
- leecode第二百三十五题(二叉搜索树的最近公共祖先)
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- Python的类的下划线命名的区别
首先,单下划线开头,这个常被用于模块中,在一个模块中以单下划线开头的变量和函数被默认当做内部函数,如果使用from module import *导入时,这部分变量和函数不会被导入.注意,如果使 ...
- C++(实验三)
Part 1 画布小球试验 程序源码 #include <iostream> #include "canvas.h" #include "ball.h&quo ...
- 常见程序入口点(OEP)特征
delphi: 55 PUSH EBP 8BEC MOV EBP,ESP 83C4 F0 ADD ESP,-10 B8 A86F4B00 ...
- vue-文字块收缩与展开功能
在设计图中要求的效果为: 文字限制超过9行即隐藏,并显示“展开”按钮,点击按钮进行切换,控制文本全部展示和部分展示 在原本的实现过程中,使用了红框内的判断方式: 页面代码: 样式则规定嵌套元素给一个死 ...
- js里面的Object基本
属性名必须是字符串,非字符串对象不能用来作为一个对象属性的键,任何非字符串对象,包括number,可通过toString()方法,类型转换成一个字符串1 1,Object基本格式 <script ...
- uva 10288 gailv
Problem F Coupons Input: standard input Output: standard output Time Limit: seconds Memory Limit: MB ...
- 下拉菜单css
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Cognos无法解密来着内容库的用户名和密码凭证
1. 问题描述 启动Cognos失败,报错代码为QE-DEF-0368. 2. 问题分析 Frame Work和Cognos Server安装在不同的目录和/或不同的机器上. 3. 解决方案 需要把S ...