题干:

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.

Non-palindromic numbers can be paired with palindromic ones via a series of operations. First, the non-palindromic number is reversed and the result is added to the original number. If the result is not a palindromic number, this is repeated until it gives a palindromic number. For example, if we start from 67, we can obtain a palindromic number in 2 steps: 67 + 76 = 143, and 143 + 341 = 484.

Given any positive integer N, you are supposed to find its paired palindromic number and the number of steps taken to find it.

Input Specification:

Each input file contains one test case. Each case consists of two positive numbers N and K, where N (≤10​10​​) is the initial numer and K (≤100) is the maximum number of steps. The numbers are separated by a space.

Output Specification:

For each test case, output two numbers, one in each line. The first number is the paired palindromic number of N, and the second number is the number of steps taken to find the palindromic number. If the palindromic number is not found after K steps, just output the number obtained at the Kth step and K instead.

Sample Input 1:

67 3

Sample Output 1:

484
2

Sample Input 2:

69 3

Sample Output 2:

1353
3

题目大意:

解题报告:

没仔细看,以为最多就100*1e10这么大。仔细一看需要上大数。写了一个字符串版本的。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int k;
string n;
string add(string a,string b) {int p = a.length(),c=0;string res(p,'0');for(int i = p-1; i>=0; i--) {res[i] = c + (a[i]-'0') + (b[i]-'0') + '0';c = 0;if(res[i] > '9') c = 1,res[i] -= 10;}if(c > 0) res = "1" + res;return res;
}
bool is(string a) {int p = a.length();for(int i = 0; i<=p/2; i++) if(a[i] != a[p-i-1]) return 0;return 1;
}
int main()
{cin>>n>>k;if(is(n)) {cout << n << endl << 0 << endl;return 0 ;}for(int i = 1; i<=k; i++) {string n2 = n;reverse(n2.begin(),n2.end());n = add(n,n2); if(is(n)) {cout << n << endl << i << endl;return 0;}}cout << n << endl << k << endl;return 0 ;
}

【PAT - 甲级1024】Palindromic Number (25分)(大数,模拟)相关推荐

  1. PAT甲级1024 Palindromic Number:[C++题解]回文串和高精度加法

    文章目录 题目分析 题目链接 题目分析 一个判断是否是回文数的函数:check,思路是使用双指针从两端分别往里走. 另一个是高精度加法函数add,传入两个vector. 另外,vector逆序构造可以 ...

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

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

  3. 【PAT甲级 BigInteger运算】1024 Palindromic Number (25 分) Java 全部AC

    题目 题解 Java 一开始用C++写的,有两个大数的测试点过不去,后来改用Java的BigInteger开挂,全部通过 import java.io.BufferedReader; import j ...

  4. 【PAT - 甲级1003】Emergency (25分)(Dijkstra,最短路条数,双权值最短路)

    题干: As an emergency rescue team leader of a city, you are given a special map of your country. The m ...

  5. 【PAT甲级A1003 】Emergency (25分)(c++)

    1003 Emergency (25分) 作者:CHEN, Yue 单位:浙江大学 代码长度限制:16 KB 时间限制:400 ms 内存限制:64 MB As an emergency rescue ...

  6. 19年春季第二题 PAT甲级 1157 Anniversary(25 分)

    英文题目 Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the cel ...

  7. 19年冬季第二题 PAT甲级 1165 Block Reversing (25分) 跟1133类似的题目

    题目 Given a singly linked list L. Let us consider every K nodes as a block (if there are less than K ...

  8. 【PAT - 甲级1010】Radix (25分)(二分,进制转化)

    题干: Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? Th ...

  9. PAT甲级1072 Gas Station (30 分):[C++题解]dijkstra算法、最短路

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 所有的dist[ ]都≤Ds:最小的dist[ ]最大; dist[ ] 总和最大. 由于加油站是字符,为了简单起见,将m个加油站编 ...

最新文章

  1. 实验4:正确的为各种属性赋值||实验7:通过abstract属性创建一个模板bean||实验8:bean之间的依赖||实验9:测试bean的作用域,分别创建单实例和多实例的bean★(测试)
  2. GraphQL 入门第一篇
  3. 科研工作者一般怎么找文献?
  4. 【Linux】一步一步学Linux——whoami命令(96)
  5. hive mysql5.7_安装并使用mysql5.7作为hive的metastore
  6. linux ioctl及ioctl command
  7. 销售服务器 以次充好 判刑,销售假冒产品怎么判刑处罚,法律怎么规定的?
  8. Windows中MySQL主从数据库搭建(三)
  9. 2022-2027年中国OLED显示面板行业发展监测及投资战略研究报告
  10. mintUI MessageBox confirm弹框确认和取消按钮的使用-回调
  11. DCO-OFDM可见光通信matlab
  12. leaf Variable、requires_grad、grad_fn的含义以及它们之间的关系
  13. jenkins cicd k8s 多分支流水线构建
  14. 查看,设置,设备的 竖屏-横屏模式 screen.orientation
  15. 在iview中render函数使用Switch功能
  16. 2020-6-6模拟赛题解
  17. Neo4j入门-以Movies Project为例
  18. nodegitgithub
  19. 985毕业,35岁创业失败,36岁回炉40岁被裁,中年夫妻无业咋办?
  20. Java项目论文+中期检查+PPT+源码等]S2SH+mysql城市公交管理系统

热门文章

  1. C# 温故而知新:Stream篇(六)
  2. EXEJ4 生成的java exe文件更换电脑后出现闪退情况解决办法
  3. 安川最小巧机器人_2020工博会,安川展品前瞻(机器人篇)
  4. dataoutputstream.write 有时无法发送_RTK实操——CORS官方网教您如何解决RTK无法固定的问题...
  5. Spring MVC使用指示符重定向
  6. java生成四则运算表达式_生成四则运算(java实现)
  7. shell 进入hadoop_Hadoop Shell命令
  8. ssm框架里面前端拿HTML写,ssm框架引入Vue,声明式渲染,标签的href拼接字符串
  9. python中sn的意思_python获取内存SN编号等信息
  10. linux内核编译后 make: 警告:检测到时钟错误.,系统时钟 make: 警告:检测到时钟错误。您的创建可能是不完整的。...