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. 《DSP using MATLAB》Problem 6.14

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  2. eclipse svn不能忽略文件及文件夹,ignore设置无效 ?

    https://blog.csdn.net/zengmingen/article/details/79025445 https://blog.csdn.net/zengmingen/article/d ...

  3. Go Example--限速

    package main import ( "fmt" "time" ) func main() { requests := make(chan int, 5) ...

  4. LeetCode - Max Area of Island

    Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...

  5. go-elasticsearch 来自官方的 golang es client

    elasticsearch 终于有了官方的golang sdk 了,地址 https://github.com/elastic/go-elasticsearch 当前还不稳定,同时主要是对于es7 的 ...

  6. DevExpress Cpicturebox或者Dev控件 PictureEdit 按比例的缩放加载图片

    方法一:     如果要加载的图片的长宽比不是太过失衡, 1.可以改变picturebox的SizeMode属性为 PictureBoxSizeMode.StretchImage, 2.或者Dev控件 ...

  7. 原码,反码,补码,及Java中数字表示方法

    原码:原码是符号位加上真值的绝对值, 即用第一位表示符号, 其余位表示值. 如:如果是八位二进制1即用00000001表示,-1即用10000001表示. 反码:正数的反码就是其本身,负数的反码是在其 ...

  8. Zabbix-2.4-安装-4

    Zabbix api 对于以上两种方式,有些人都不选,倾向于使用第三种:使用zabbix api加上这个监控在把这台机器删除了,然后discovery和自动注册的都关闭了再换一种方式把它加进去,zab ...

  9. TypeScript 之 模块

    https://m.runoob.com/manual/gitbook/TypeScript/_book/doc/handbook/Modules.html 外部模块简写 外部模块简写:declare ...

  10. java标识字

    JAVA中,标识符, 指用于给变量.类.方法名 等命名的名称. 1,标识以数字,字符,下划线,以及美元$符组成.(不能包括@.%.空格等),不能以数字开头. 2,不能与JAVA关键字重复 3,严格区分 ...