题意:略。

思路:大整数相加,回文数判断。对首次输入的数也要判断其是否是回文数,故这里用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. QQ钱包,微信,京东钱包,百度钱包,支付宝AGENT

    微信Mozilla/5.0 (Linux; Android 7.0; LON-AL00 Build/HUAWEILON-AL00; wv) AppleWebKit/537.36 (KHTML, lik ...

  2. ASP.NET动态创建数据库和表

    using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; usin ...

  3. 在Windows Server 2012上安装SharePoint 2010 SP1

    现在很多企业的系统都开始用上了Windows 2012,最近公司需要建立一个门户系统,一开始就想到了微软的SharePoint2010,这玩意确实非常强悍,2008已经褪去,当然直接在Windows ...

  4. poj3311 状压dp+floyd

    先floyd预处理一遍dis,枚举所有状态,dp[ i ] [ j ]表示 以  j  为终点的状态 i 使用最小的时间 #include<map> #include<set> ...

  5. 关于shortcut icon和icon代码的区别介绍

    语句一:<link rel="shortcut icon" href="favicon.ico" /> 语句二:<link rel=" ...

  6. HDU 1410 PK武林盟主

    Problem Description 枫之羽认为自己很强,想当武林盟主,于是找现任武林盟主氢氧化铜挑战.氢氧化铜欣然接受了挑战,两人约好于下个月的月圆之夜在HDU校园内的三根柱子上进行决战.这场PK ...

  7. Database项目中关于Procedure sp_refreshsqlmodule_internal的错误

    最近项目中发现一怪问题,使用DB项目发布数据库时,总提示 “(110,1): SQL72014: .Net SqlClient Data Provider: Msg 1222, Level 16, S ...

  8. 【Codeforces】894D. Ralph And His Tour in Binary Country 思维+二分

    题意 给定一棵$n$个节点完全二叉树,$m$次询问,每次询问从$a$节点到其它所有节点(包括自身)的距离$L$与给定$H_a$之差$H_a-L$大于$0$的值之和 对整棵树从叶子节点到父节点从上往下预 ...

  9. Android的布局方式

    1.LinearLayout(线性布局) android:orientation="vertical" //布局 android:layout_width="wrap_c ...

  10. setInterval(callback(),time)

    最近在写一个需求的时候,出了点小小的问题,在这做个记录. 对于定时函数setInterval()大家应该都不陌生,setInterval(callback(),time)就是说设置一个定时器,每隔ti ...