输入即为回文的情况要考虑

 #include <iostream>
#include <algorithm> //reverse
using namespace std;
string n;
int k;
string strAdd(string a){
string b;
int num,cc=;
int len=a.size();
for(int i=;i<len;i++){
num=a[i]+a[len-i-]-*''+cc;
cc=num/;
b.push_back(num%+'');
}
if(cc!=) b.push_back('');
reverse(b.begin(),b.end());
return b;
}
bool isPali(string &a){
int len=a.size();
for(int i=;i<len/;i++){
if(a[i]==a[len--i]){continue;}
else{return false;}
}
return true;
}
int main()
{
cin>>n>>k;
int c=k;
string result=n;
if(isPali(result)) {cout<<result<<endl<<"";return ;}
while(c--){
result=strAdd(result);
if(isPali(result))break;
}
if(c<=){
cout<<result<<endl;
cout<<k;
}else{
cout<<result<<endl;
cout<<(k-c);
}
return ;
}

PAT1024. Palindromic Number (25)的更多相关文章

  1. PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)

    1024 Palindromic Number (25 分)   A number that will be the same when it is written forwards or backw ...

  2. 1024. Palindromic Number (25)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  3. 1024 Palindromic Number (25)(25 point(s))

    problem A number that will be the same when it is written forwards or backwards is known as a Palind ...

  4. 【PAT】1024. Palindromic Number (25)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  5. PAT Advanced 1024 Palindromic Number (25) [数学问题-⼤整数相加]

    题目 A number that will be the same when it is written forwards or backwards is known as a Palindromic ...

  6. 1024 Palindromic Number (25 分)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  7. PAT1024. Palindromic Number

    //自己方法只能拿到15分后边老是又过不了的点,用了网上别人的方法,用库函数的翻转reverse(),参数分别是起始位置个结束位置,注意只能在原存储空间翻转,即比较对称时,再生请一个空间,将原来字符串 ...

  8. PAT (Advanced Level) 1024. Palindromic Number (25)

    手动模拟加法高精度. 注意:如果输入数字的就是回文,这个时候输出0步. #include<iostream> #include<cstring> #include<cma ...

  9. PAT甲题题解-1024. Palindromic Number (25)-大数运算

    大数据加法给一个数num和最大迭代数k每次num=num+num的倒序,判断此时的num是否是回文数字,是则输出此时的数字和迭代次数如果k次结束还没找到回文数字,输出此时的数字和k 如果num一开始是 ...

随机推荐

  1. jmeter 响应数据更换显示类型(json、html、text)

    .默认情况下是Text格式 2.修改为json格式显示

  2. echarts之series,markLine、markPoint

    一.标记线和标志点 markLine 标记线 标记线的添加,如最大值.最小值.平均值的标记线 symbol 标记的图形. data->type 特殊的标注类型,用于标注最大值最小值等. 可选: ...

  3. SpringBoot使用H2内嵌数据库

    1.驱动 我们知道,JDBC是JDK自带的接口规范,不同的数据库有不同的实现,只需要引入相应的驱动包即可. 在使用MySQL数据库时,引入的是MySQL驱动,相应的,使用H2数据库时,也需要引入H2驱 ...

  4. Exploiting second-order SQL injection 利用二阶注入获取数据库版本信息 SQL Injection Attacks and Defense Second Edition

    w SQL Injection Attacks and Defense  Second Edition Exploiting second-order SQL injection Virtually ...

  5. DevExpress控件-lookupedit的使用方法详解(图文)转http://blog.csdn.net/qq395537505/article/details/50920508

    绑定数据源: lookupedit.Properties.ValueMember = 实际要用的字段; //相当于editvalue lookupedit.Properties.DisplayMemb ...

  6. 我的Android进阶之旅------>Android中高低API版本兼容使用@TargetApi或者@SuppressLint("NewApi")

    Android中高低API版本兼容使用@TargetApi或者@SuppressLint("NewApi") 例如:AndroidManifest.xml中,我们配置了sdk版本的 ...

  7. Linux中的系统默认日志

    /var/log/cron 记录了系统定时任务相关的日志 /var/log/cups 记录了打印信息的日志 /var/log/dmesg 记录了系统在开机时内核自检的信息,可以通过dmesg命令直接查 ...

  8. Linux中进程在前后台的切换

    把进程放入后台执行 tar -zcf etc.tar.gz /etc &把进程放入后台暂停 在命令执行的过程中,按下ctrl+z 查看后台的命令 jobs[root@localhost tem ...

  9. boost之实用工具

    1.noncopyable用于禁止复制和拷贝的类继承.声明拷贝和赋值函数为私有,将运行时的错误转化为编译期的错误. #include <iostream> #include <boo ...

  10. zabbix-2.4.8-1添加tcp状态监控

    1.安装zabbix-agentyum -y install zabbix-2.4.8-1.el6.x86_64.rpm zabbix-agent-2.4.8-1.el6.x86_64.rpm2.编辑 ...