PAT 1136 A Delayed Palindrome
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 with 0 for all i and ak>0. Then N is palindromic if and only if ai=ak−i for all i. Zero is written 0 and is also palindromic by definition.
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. Such number is called a delayed palindrome. (Quoted from https://en.wikipedia.org/wiki/Palindromic_number )
Given any positive integer, you are supposed to find its paired palindromic number.
Input Specification:
Each input file contains one test case which gives a positive integer no more than 1000 digits.
Output Specification:
For each test case, print line by line the process of finding the palindromic number. The format of each line is the following:
A + B = C
where A
is the original number, B
is the reversed A
, and C
is their sum. A
starts being the input number, and this process ends until C
becomes a palindromic number -- in this case we print in the last line C is a palindromic number.
; or if a palindromic number cannot be found in 10 iterations, print Not found in 10 iterations.
instead.
Sample Input 1:
97152
Sample Output 1:
97152 + 25179 = 122331
122331 + 133221 = 255552
255552 is a palindromic number.
Sample Input 2:
196
Sample Output 2:
196 + 691 = 887
887 + 788 = 1675
1675 + 5761 = 7436
7436 + 6347 = 13783
13783 + 38731 = 52514
52514 + 41525 = 94039
94039 + 93049 = 187088
187088 + 880781 = 1067869
1067869 + 9687601 = 10755470
10755470 + 07455701 = 18211171
Not found in 10 iterations.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; string reversestr(string s){
string res = "";
for(auto x:s){
res = x+res;
}
return res;
} string strplus(string a,string b){
string res = "";
int len = a.size();
int jinwei = ;
for(int i=len-;i >= ;i--){
int numa = a[i] - '';
int numb = b[i] - '';
int numsum = numa + numb + jinwei;
jinwei = numsum/;
int add = numsum%;
res = to_string(add) + res;
}
if(jinwei) res = ""+res;
return res;
} int main(){
string s;
cin >> s;
int cnt = ; while(){
string t = reversestr(s);
if(t == s) {
printf("%s is a palindromic number.", s.c_str());
break;
} string kkp = strplus(s,t); printf("%s + %s = %s\n",s.c_str(),t.c_str(),kkp.c_str()); s = kkp; cnt++;
if(cnt >= ){
printf("Not found in 10 iterations.");
break;
}
} return ;
}
大数相加突然变得好容易啊。。。
PAT 1136 A Delayed Palindrome的更多相关文章
- PAT 1136 A Delayed Palindrome[简单]
1136 A Delayed Palindrome (20 分) Consider a positive integer N written in standard notation with k+1 ...
- pat 1136 A Delayed Palindrome(20 分)
1136 A Delayed Palindrome(20 分) Consider a positive integer N written in standard notation with k+1 ...
- PAT甲级:1136 A Delayed Palindrome (20分)
PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...
- PAT A1136 A Delayed Palindrome (20 分)——回文,大整数
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
- 1136 A Delayed Palindrome (20 分)
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
- 1136 A Delayed Palindrome (20 分)
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
- 1136 A Delayed Palindrome
题意:略. 思路:大整数相加,回文数判断.对首次输入的数也要判断其是否是回文数,故这里用do...while,而不用while. 代码: #include <iostream> #incl ...
- PAT1136:A Delayed Palindrome
1136. A Delayed Palindrome (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- A1136. Delayed Palindrome
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
随机推荐
- 为fastdfs文件服务器新增一个storage
一.前言: 前期,已经搭建好了一套fastdfs文件服务器,一个tracker和一个storage,且部署在同一台服务器上,已经正式投入运行快半年了,1T的空间现在只剩下100G容量了,现在需要扩容, ...
- WinForm窗体权限控制的简单实现
一.建立两张表 //存放要控制的窗体控件 CREATE TABLE [dbo].[AuthControl] ( [Id] INT IDENTITY (1, 1) NOT NULL, [NiceName ...
- 记自己利用hexo和github搭建个人博客的过程
--------------------------------------可能我书写的方式跟别人顺序不一样,但这是我的成功经验------------------------------------ ...
- python各种转义字符
- Node.js基础学习四之注册功能
前言:在Node.js学习(二)和(三)中介绍了如何在Node.js 中获取登录的用户名和密码与数据库进行验证并返回数据给客户端 需求:实现注册功能 为了区分登录和注册是两个不同的请求,在端口后面加上 ...
- Literal绑定数据
前台: <asp:Literal ID = "ChiCunShow" runat = "server"></asp:Literal> 后 ...
- pyautogui
pip install PyGetWindow==0.0.1 pip install pyautogui https://www.cnblogs.com/dcb3688/p/4607980.html
- 【js】版本号对比处理方案
今天在处理一个bug问题,适配客户端版本:若版本号未达到,则不可运行该功能,若达到则可运行. 版本号规则如下:(一般统一为2个点,其他的是数字,版本号从高位到低位,首位越大则越大,首位相同则对比下一位 ...
- 完整的多文件上传实例(java版)
昨天刚刚做了一个文件列表上传,后端很简单,用 MultipartFile[] files 获取文件流数组,后端就当IO流操作就可以,似乎好像没啥好写的,但是!!!!!前端是真的糙单.要是自己写一个前端 ...
- jQuery Validate和Thymeleaf相关
jQuery Validate https://www.cnblogs.com/liuhongfeng/p/5135676.html https://www.cnblogs.com/linjiqin/ ...