题意:略。

思路:大整数相加,回文数判断。对首次输入的数也要判断其是否是回文数,故这里用do...while,而不用while。

代码:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

bool judge(const string &str)
{
    ,j=str.size()-;
    while(i<=j){
        if(str[i]!=str[j]) return false;
        i++;
        j--;
    }
    return true;
}

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

int main()
{
    string s1,s2;
    cin>>s1;
    ;
    do{
        if(judge(s1)){
            cout<<s1<<" is a palindromic number.\n";
            break;
        }
        s2=s1;
        reverse(s2.begin(),s2.end());
        string sum=add(s1,s2);
        cout<<s1<<" + "<<s2<<" = "<<sum<<"\n";
        s1=sum;
    }while(--cnt);
    ) cout<<"Not found in 10 iterations.\n";
    ;
}

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

  2. PAT 1136 A Delayed Palindrome[简单]

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

  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 (20分)

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

  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. PAT1136:A Delayed Palindrome

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

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

  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. virtio guest side implementation: PCI, virtio device, virtio net and virtqueue

    With the publishing of OASIS virtio specification version 1.0, virtio made another big step in becom ...

  2. MySQL主从配置实现(同一台主机)

    ////////////////////MySQL主从(同一台主机)////////////////////// 1.安装配置MySQL参考之前步骤搭建MySQL服务为了做实验方便,我们在同一台机器上 ...

  3. 一些官方的github地址

    阿里巴巴开源github地址:https://github.com/alibaba 腾讯开源github地址:https://github.com/Tencent 奇虎360github地址:http ...

  4. thinkphp3.2.3 定时任务重新加载, 无法加载新的定时任务的问题

    thinkphp3.2.3 的定时任务有个坑,一旦你改名定时任何或者路径,新的定时任务将无法加载,无论你重启php还是重启nginx,甚至重启服务器,都不行. 原因是你要删掉一个类似lock文件,才可 ...

  5. 新东方雅思词汇---6.3、brilli

    新东方雅思词汇---6.3.brilli 一.总结 一句话总结: 发光 brilliant 英 [ˈbrɪlɪənt]  美 ['brɪljənt]  adj. 灿烂的,闪耀的:杰出的:有才气的:精彩 ...

  6. legend---十二、js中的js语句和函数和ready函数的关系是什么

    legend---十二.js中的js语句和函数和ready函数的关系是什么 一.总结 一句话总结: 函数和全局变量不必放到ready函数中 语句(调用函数和全局变量)的必须放到ready函数中 1.在 ...

  7. 复制文件夹的方法 .net

    void CopyDirectory(string SourcePath,string DestinationPath) { //创建所有目录 foreach(string dirPath inDir ...

  8. OSI七层模型及应用

    应用层:提供访问网络服务的接口.例如telnet. 表示层:提供数据格式转化服务.例如压缩和解压缩. 会话层:提供回话实体的连接服务,进行访问验证和会话管理.例如服务器验证用户登录和断点续传. 传输层 ...

  9. Linux操作系统中的文件目录结构详细介绍

    "/" :Linux文件系统的入口.也是最高一级的目录. "/bin":基本系统所需要的命令,功能和"/usr/bin"类似,这个目录下的文 ...

  10. 一次完整的HTTP请求

    HTTP通信机制是在一次完整的HTTP通信过程中,Web浏览器与Web服务器之间将完成下列7个步骤: 1:建立TCP连接,TCP的三次握手 在HTTP工作开始之前,Web浏览器首先要通过网络与Web服 ...