1136 A Delayed Palindrome (20 分)
 

Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ with 0 for all i and a​k​​>0. Then N is palindromic if and only if a​i​​=a​k−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.
作者: CHEN, Yue
单位: 浙江大学
时间限制: 400 ms
内存限制: 64 MB
#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的更多相关文章

  1. PAT 1136 A Delayed Palindrome[简单]

    1136 A Delayed Palindrome (20 分) Consider a positive integer N written in standard notation with k+1 ...

  2. pat 1136 A Delayed Palindrome(20 分)

    1136 A Delayed Palindrome(20 分) Consider a positive integer N written in standard notation with k+1 ...

  3. PAT甲级:1136 A Delayed Palindrome (20分)

    PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...

  4. PAT A1136 A Delayed Palindrome (20 分)——回文,大整数

    Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ ...

  5. 1136 A Delayed Palindrome (20 分)

    Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ ...

  6. 1136 A Delayed Palindrome (20 分)

    Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ ...

  7. 1136 A Delayed Palindrome

    题意:略. 思路:大整数相加,回文数判断.对首次输入的数也要判断其是否是回文数,故这里用do...while,而不用while. 代码: #include <iostream> #incl ...

  8. PAT1136:A Delayed Palindrome

    1136. A Delayed Palindrome (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  9. A1136. Delayed Palindrome

    Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ ...

随机推荐

  1. IO流(一)

    一.异常 概述 异常就是Java程序在运行过程中出现的错误. 由来 问题也是现实生活中一个具体事务,也可以通过java的类的形式进行描述,并封装成对象.其实就是Java对不正常情况进行描述后的对象体现 ...

  2. 浏览器对象模型BOM总结

    BOMwindows对象document对象location对象screen对象 Windows对象 1.窗口操作 移动指定的距离:window.moveBy(10,20); //向右移动10像素,向 ...

  3. you've successfully authenticated, but Gitee.com does not provide she access.

    如果都是正常的生成ssh的操作,还是会报这个错误,那么就是.... 你没更改文件夹的权限,这个坑跳了很久(汗...) sudo chmod 777 -r 文件夹

  4. python locust 性能测试:HOOKS<钩子方法>

    为locust中不同类型的事件,提供的钩子方法: from locust import TaskSet, task, events, Locust from locust.clients import ...

  5. 分享一个基于ssm框架下的webService接口开发

    首先肯定是导入相关jar包 cxf-core-3.1.9.jar cxf-rt-bindings-soap-3.1.9.jar cxf-rt-bindings-xml-3.1.9.jar cxf-rt ...

  6. Linux中DDNS配置

    1.实验拓扑结构 图1 实验拓扑图 2.项目要求 通过系统的搭建,能够为Web Server动态更新DNS信息. 3.项目开展思路(思维导图) 图2 DDNS实验思维导图 4.实验步骤 (1) 基础网 ...

  7. tomcat启动命令行中文乱码

    1.找到${CATALINA_HOME}/conf/logging.properties 2.添加语句:java.util.logging.ConsoleHandler.encoding = GBK ...

  8. kbmmemtable sorton 报错 : List index out of bounds

    同一数据集,不同的排序条件,有的可以,但某一条件,却能100%重现报错. procedure TkbmIndex.InternalFastQuickSort(const L,R:Integer); v ...

  9. 湘潭邀请赛+蓝桥国赛总结暨ACM退役总结

    湘潭邀请赛已经过去三个星期,蓝桥也在上个星期结束,今天也是时候写一下总结了,这应该也是我的退役总结了~ --------------------------------湘潭邀请赛----------- ...

  10. showDialog 必须Stateful

    showDialog 必须Stateful 因为需要context