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.

分析:大数模拟,最后一个测试点应该是大数边界,因为数可能是1000位的,所以如果用int 和long long 都会超出范围。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<unordered_set>
#include<map>
#include<vector>
#include<set>
using namespace std;
string rev(string s){
    reverse(s.begin(),s.end());
    return s;
}

string add(string s1,string s2){
    ;
    string s=s1;
    ;i>=;i--){
        '+carry;
        s[i]=temp%+';
        carry=temp/;
    }
    ) s='+s;
    return s;
}

bool ispali(string s){
    int len=s.length();
    ;i<len;i++){
        ]){
            return false;
        }
    }
    return true;
}

int main(){
#ifdef ONLINE_JUDGE
#else
    freopen("1.txt", "r", stdin);
#endif
    string num,s;
    cin>>num;
    if(num==rev(num)){
        cout<<num<<" is a palindromic number.";
        ;
    }
    ;
    bool flag=false;
    while(k--){
        s=rev(num);
        string sum=add(s,num);
        flag=ispali(sum);
        cout<<num<<" + "<<s<<" = "<<sum<<endl;
        if(flag==true){
            cout<<sum<<" is a palindromic number.";
            break;
        }
        num=sum;
    }
    ){
        cout<<"Not found in 10 iterations.";
    }

    ;
}

1136 A Delayed Palindrome (20 分)的更多相关文章

  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 ...

  2. PAT 1136 A Delayed Palindrome

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

  3. pat 1136 A Delayed Palindrome(20 分)

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

  4. PAT 1136 A Delayed Palindrome[简单]

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

  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

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

  7. PAT1136:A Delayed Palindrome

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

  8. PAT_A1136#A Delayed Palindrome

    Source: PAT_A1136 A Delayed Palindrome (20 分) Description: Consider a positive integer N written in ...

  9. 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​​ ...

随机推荐

  1. LeetCode - Find K Closest Elements

    Given a sorted array, two integers k and x, find the k closest elements to x in the array. The resul ...

  2. Python知识点整理,基础5 - 文件操作

  3. day39KNN算法和其他的算法

    PS: 1.现在明白为什么其他的同学一直都在做数字图像处理,matlab这种东西了,因为机器学习,其他底层主要是做预先处理,然后调用某一个算法 2.感觉knn算法就是根据先验数据计算下一个跟自己一样不 ...

  4. spring获取jdbc链接底层原理

    获取连接池的连接二种逻辑 1.一个事务中,一个连接 (底层逻辑:threadlocal存储  里面是map: key是数据源,value:链接) map存储应该是为多数据源使用的2.没有事务的serv ...

  5. 利用反射C#获取事件列表

    在程序设计中有时候需要动态订阅客户自己的事件,调用完成后又要删除以前订阅的事件.因为如果不删除,有时会造成事件是会重复订阅,导致程序运行异常.一个办法是用反射来控件事件列表.清空方法代码如下: /// ...

  6. 基于.NET平台常用的框架整理 【转载】

    [转载] http://www.cnblogs.com/hgmyz/p/5313983.html 自从学习.NET以来,优雅的编程风格,极度简单的可扩展性,足够强大开发工具,极小的学习曲线,让我对这个 ...

  7. 23 模块 os sys pickle json

    一.   os模块 主要是针对操作系统的 用于文件操作 二.    sys 模块 模块的查找路径   sys.path 三   pickle 模块 1.  pickle.dumps(对象) 序列化  ...

  8. java考试感受

    开学不久,我们进行了一次java程序考试.在此之前,老师要求我们在假期自学java并提前发了一个考试样卷,要求用数组编写一个学生信息管理系统并能够实现一系列的功能.由于我早早的便完成了这道题.因此对这 ...

  9. H5公共样式,用于所有H5开发页面

    @charset "UTF-8"; /* H5公共样式,用于所有H5开发页面*/ html { font-family: "Microsoft Yahei", ...

  10. spring boot 2 返回Date 格式化问题

    以前 返回数据把Date  转成 long的时间毫秒数.现在是格式化成了字符串. 默认的结果:"createDate": "2018-09-06T10:04:25.000 ...