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 ...
随机推荐
- Vue-admin工作整理(十): Vuex-Actions(模拟接口请求实现组件字段更新)
思路:通过提交一个 mutation,而不是直接变更状态,它可以包括异步操作,通过请求接口,定义一个方法,第一个参数为对象,在里面能够提取到一些东西,比如:commit,这是一个方法,调用这个comm ...
- python - xml转excel
xml转excel,可以用xml.etree.ElementTree去解析xml文件,然后用xlwt写入excel 示例:ConvConfig.xml <Conveyor_Channel_1&g ...
- English trip EM1 - PE2 My My name is... Teacher:Lamb Key: introduce myself
课上内容(Lesson) Lamb let us does introduce myself. Make a "hangman" game at warm-up . How to ...
- python正则表达式 - re
1,匹配符号 任意字符 . : 任意字符,除了\n,flags设置为DOTALL(S)可以让.匹配\n []字符集合,字符组:规范/元字符不同于正则式主体 [0-9] : 数字 [A-Z] : 大写字 ...
- SQLServer2008 查询分析器内容未保存,查找分析器内容
位置:C:\Users\Administrator\Documents\SQL Server Management Studio\Backup Files\Solution1
- 关于lower_bound( )和upper_bound( )的常见用法
lower_bound( )和upper_bound( )都是利用二分查找的方法在一个排好序的数组中进行查找的. 在从小到大的排序数组中, lower_bound( begin,end,num):从数 ...
- MariaDB主从复制,redis发布订阅,持久化,以及主从同步
一. MariaDB主从复制 mysql基本操作 1 连接数据库 mysql -u root -p -h 127.0.0.1 mysql -u root -p -h 192.168.12.60 2 ...
- IOCP模型与网络编
一.前言: 在老师分配任务(“尝试利用IOCP模型写出服务端和客户端的代码”)给我时,脑子一片空白,并不知道什么是IOCP模型,会不会是像软件设计模式里面的工厂模式,装饰模式之类的那些呢 ...
- PAT 1124 Raffle for Weibo Followers
1124 Raffle for Weibo Followers (20 分) John got a full mark on PAT. He was so happy that he decide ...
- python中对文件和文件夹的操作
一.说明 python中主要通过os模块和shutil模块两个模块对文件进行相关操作,移动.复制.删除.重命名.比较大的文件通过命令操作可以节省时间,提高效率. 二.实例对文件夹中文件的拷贝 from ...