题目

题解 Java

一开始用C++写的,有两个大数的测试点过不去,后来改用Java的BigInteger开挂,全部通过

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;public class Main {public static void main(String[] args) throws IOException {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));String str = br.readLine();String[] arr = str.split(" ");BigInteger num = new BigInteger(arr[0]);int step = Integer.parseInt(arr[1]);// 翻转for (int i = 0; i < step; i++) {BigInteger tmp = new BigInteger("" + num);BigInteger rev = new BigInteger("" + 0);while (!(num.compareTo(BigInteger.ZERO) == 0)) {// 判断是否为0rev = rev.multiply(new BigInteger("" + 10));rev = rev.add(num.mod(new BigInteger("" + 10)));num = num.divide(new BigInteger("" + 10));}// 判断是否回文:翻转后相同//System.out.println(tmp + "---" + rev);if (tmp.compareTo(rev) == 0) {System.out.println(rev + "\n" + i);return;} else {// 相加num = tmp.add(rev);}}System.out.println(num + "\n" + step);}
}

题解 C++

有两个测试点过不去

#include<iostream>
using namespace std;
int main() {long long int num, step;cin >> num >> step;//翻转for (int i = 0; i < step; i++) {long long int tmp = num;long long int rev = 0;while (num != 0) {rev *= 10;rev += num % 10;num /= 10;}//判断是否回文:翻转后相同if (tmp == rev) {cout << rev << "\n" << i;return 0;}else {//相加num = tmp + rev;}}cout << num <<"\n"<< step;system("pause");
}

【PAT甲级 BigInteger运算】1024 Palindromic Number (25 分) Java 全部AC相关推荐

  1. 【题意分析】1024 Palindromic Number (25 分)_38行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 A number that will be the same when it is written forwards or bac ...

  2. PAT甲级1066 Root of AVL Tree (25分):[C++题解]建立平衡树(AVL树)

    文章目录 题目分析 题目链接 题目分析 图片来源:acwing 分析 平衡树(AVL树)是平衡二叉搜索树的简称,当然需要满足二叉搜索树的性质,左子树小于根,根小于等于右子树:然后还要满足平衡树的基本特 ...

  3. 【PAT - 甲级1024】Palindromic Number (25分)(大数,模拟)

    题干: A number that will be the same when it is written forwards or backwards is known as a Palindromi ...

  4. PAT甲级1038 Recover the Smallest Number (30 分):[C++题解]贪心、排列成最小的数、字符串

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 贪心: 对于字符串a和b,如果 a+b < b+a (这里+代表字符串中的连接)代表字典序更小.举例 a = 321 , b ...

  5. 【PAT甲级 BigInteger】1019 General Palindromic Number (20 分) Java版 7/7通过

    题目 一开始只使用了Long,有后面四个测试点过不去,后来换了BigInteger,就通过了. 这题用Java的BigInteger做,可以操作任意长度的数字,感觉有一点取巧了. 如果C或者C++的话 ...

  6. 【PAT甲级 进制转换】1019 General Palindromic Number (20 分) Java版 7/7通过

    题目 这道题可以说是非常友善了,说白了是个水题.题目没什么坑,一次通过,主要思想就是: 输入两个数:num和base 将num按照base进制转换,得到arr 判断arr是否是一个回文数,并且输出这个 ...

  7. 【PAT - 甲级1017】Queueing at Bank (25分)(优先队列,模拟)

    题干: Suppose a bank has K windows open for service. There is a yellow line in front of the windows wh ...

  8. 【PAT甲级 - 1013】Battle Over Cities (25分)(并查集)

    题干: It is vitally important to have all the cities connected by highways in a war. If a city is occu ...

  9. PAT甲级 -- 1002 A+B for Polynomials (25 分)

    This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each ...

最新文章

  1. LINUX进程调度分析源码,Linux 实时调度(源码分析)
  2. 使用ajax和history.pushState无刷新改变页面URL
  3. .Net微信开发之通过UnionID机制,解决用户在不同公众号,或在公众号、移动应用之间帐号统一问题...
  4. 【PAT甲级 补全前导0 vector作为函数参数】1025 PAT Ranking (25 分) Java、C++
  5. SAP Commerce Cloud 产品明细页面设计概述
  6. latex生成的pdf论文在打印时页码混乱的解决方法
  7. slickedit背景颜色和当前关键字高亮
  8. 新加坡经验:大数据时代政府的角色
  9. 关于感冒和流感的一些记录
  10. IEEE Access 算法 伪代码排版出错
  11. 关于阿里云业务数据分析
  12. stm32 步进电机控制,S曲线加减速,匀加速运动
  13. 中职学校计算机基础的重要性,自学能力论文,关于浅淡培养中职学生计算机自学能力的重要性和方法相关参考文献资料-免费论文范文...
  14. UML 之 顺序图(Sequence Diagram)
  15. IPv4与IPv6之间的区别
  16. ZCMU--1930: 帽子戏法(C语言)
  17. 应用程序无法正常启动(0xc000007b)。请单击“确定”关闭应用程序。——最新完美解决方案!
  18. No enclosing instance of type TextRunnable is accessible. Must qualify the allocation with an enclo
  19. 计算机网络基础案例启示,《计算机网络基础及典型案例》理工大学出版社.pdf...
  20. 御龙在天以前服务器信息,细数御龙在天的名人以及其崛起的服务器

热门文章

  1. HYSBZ - 1026 windy数(数位dp)
  2. 数据分析与挖掘理论-概述
  3. VS2019-写opengl时Bugs合集(持续更新)
  4. java数据同步处理_Java如何处理多线程的数据同步问题
  5. [luogu4389]付公主的背包
  6. 14.IDA-XREF(交叉引用)概述
  7. shlwapi常用的操作路径函数
  8. Windbg教程-调试非托管程序的基本命令中
  9. 搞懂 SQL 查询优化原理分析,秒速处理大数据量查询
  10. Sping+ActiveMQ整合