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 (≤) is the initial numer and K (≤) 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
题目分析:大数加法 把是否进1记录就好了
 #include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
using namespace std;
string Add(string s1, string s2)
{
int flag = ;
int len = s1.length();
for (int i = len - ; i >= ; i--){
int temp = flag+s1[i] - '' + s2[i] - '';
if (temp > ){
s1[i] = (temp % ) + '';
flag = ;
}
else {
s1[i] = temp + '';
flag = ;
}
}
if (flag)return '' + s1;
else
return s1;
}
int main()
{
string N;
int K;
cin >> N >> K;
int i = ;
for (; i < K; i++){
string s =N;
reverse(s.begin(), s.end());
if (s == N)
break;
else
N = Add(N, s);
}
cout << N << endl << i;
}

1024 Palindromic Number (25 分)的更多相关文章

  1. PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)

    1024 Palindromic Number (25 分)   A number that will be the same when it is written forwards or backw ...

  2. 【PAT甲级】1024 Palindromic Number (25 分)

    题意: 输入两个正整数N和K(N<=1e10,k<=100),求K次内N和N的反置相加能否得到一个回文数,输出这个数和最小的操作次数. trick: 1e10的数字相加100次可能达到1e ...

  3. 1024. Palindromic Number (25)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  4. 1024 Palindromic Number (25)(25 point(s))

    problem A number that will be the same when it is written forwards or backwards is known as a Palind ...

  5. 【PAT】1024. Palindromic Number (25)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  6. PAT Advanced 1024 Palindromic Number (25) [数学问题-⼤整数相加]

    题目 A number that will be the same when it is written forwards or backwards is known as a Palindromic ...

  7. PAT (Advanced Level) 1024. Palindromic Number (25)

    手动模拟加法高精度. 注意:如果输入数字的就是回文,这个时候输出0步. #include<iostream> #include<cstring> #include<cma ...

  8. PAT甲题题解-1024. Palindromic Number (25)-大数运算

    大数据加法给一个数num和最大迭代数k每次num=num+num的倒序,判断此时的num是否是回文数字,是则输出此时的数字和迭代次数如果k次结束还没找到回文数字,输出此时的数字和k 如果num一开始是 ...

  9. PAT 甲级 1024 Palindromic Number

    1024. Palindromic Number (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

随机推荐

  1. 2019年高校微信小程序开发大赛学习笔记

    学做小程序(学堂在线笔记)一.传统布局 text-align:center //水平居中 margin-bottom: 60px //设置间距 二.弹性盒子布局 display:flex; flex- ...

  2. echarts-liquidfill 水球显示小数点

    使用echarts-liquidfill.js的水球,水球上显示的文字可以使用chartOption.series[0].label.normal.formatter设置,想显示什么显示什么. var ...

  3. c 将年月日转化为星期

    /*得到年月日转化为星期几*/ LOCAL ulong_t DateWeekGet(ulong_t year,ulong_t month,ulong_t day) { ulong_t c = ; ul ...

  4. svn 追责神器 blame vscode - SVN Gutter

    svn 追责神器 blame vscode - SVN Gutter

  5. SSM整合搭建(二)

    本页来衔接上一页继续来搭建SSM,再提一下大家如果不详细可以再去看视频哦,B站就有 之后我们来配置SpringMVC的配置文件,主要是配置跳转的逻辑 先扫描所有的业务逻辑组件 我们要用SpringMV ...

  6. Natas29 Writeup(Perl命令注入、00截断、绕过过滤)

    Natas29: 本关打开后,可以看到一个下拉列表,选择不同的内容,会得到不同的大量文本的页面. 观察url部分:http://natas29.natas.labs.overthewire.org/i ...

  7. 什么是Hibernate

    Hibernate是一个基于JDBC的主流持久性框架,是一个优秀的ORM(object relation mapping)(对象关系映射)实现 ORM就是通过java对象映射到数据库表中,通过操作ja ...

  8. 全文搜索技术--Solr7.1之配置中文分析器

    前言:中国文化博大精深,但是solr只能一个一个的识别,而是更加符合中国人的习惯,所以加了中文分析器. 1.安装中文分词器 第一步:把中文分词器(ik-analyzer-solr7-7.x.jar)/ ...

  9. bash中的if条件语句报错[: missing `]'

    这是我的一个小demo #!/bin/bash read -p "请输入3个数:" n1 n2 n3 if [ $n1 -gt $n2 ] && [ $n1 -gt ...

  10. 一个简单的方法去掉angular application中URLs的hashtag

    本文转载自:Pretty URLs in AngularJS: Removing the # By default, AngularJS will route URLs with a hashtag. ...