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

 #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. iOS-ASIHTTPRequest框架学习

    本文转载至 http://www.cnblogs.com/A-Long-Way-Chris/p/3539679.html 前段时间在公司的产品中支持了够快网盘,用于云盘存储. 在这个过程中,学习到了很 ...

  2. Linux常用命令及Vim使用

    1.ls 命令 --------------------------------------------------------------------- ls以默认方式显示当前目录文件列表 ls - ...

  3. 05、(通过nat123软件) 实现用自己电脑搭建一个网站

    (通过nat123软件) 实现用自己电脑搭建一个网站 准备: Tomcat:这个是web容器,其实有了这个就已经让电脑成为服务器了,在自己电脑上可以通过 localhost:8080/xxx 来访问自 ...

  4. 用javascript复制富文本

    由于项目需求,希望能够用javascript复制富文本格式的数据,例如全选一个网页Ctrl+C, Ctrl+V到一个word文档中,数据还是原来的格式,显示出来的样子也都和原来一样.现在希望使用jav ...

  5. IDEA错误的将所有代码文件都加入版本控制

    1.问题: IDEA将从Git上拉取的所有代码文件都加入版本控制里,而这些文件和远程服务器没有任何区别: 2.原因: 后来发现,虽然项目使用的是Git的版本控制,但是异常模块都是使用SVN的版本控制: ...

  6. spring cloud 微服务应用间通讯

    SpringCloud 应用间通信基于HTTP的Restful调用方式有两种,RestTemplate与Feign. 1.RestTemplate应用间通讯 通过 @LoadBalanced,可在re ...

  7. Selenium IDE的使用

    Selenium IDE 的作用 Selenium IDE 是Firefox 浏览器的一个插件, 它会记录你对Firefox的操作,并且可以回放它的操作. 在实际自动化测试中,不会用Selenium ...

  8. JavaWeb 之监听器

    1. JavaWeb 监听器概述 在 JavaWeb 被监听的事件源为: ServletContext, HttpSession, ServletRequest, 即三大域对象. 监听域对象" ...

  9. js验证表单大全3

    2 >表单提交验证类  2.1 表单项不能为空 <scriptlanguage="javascript"> <!-- function CheckForm( ...

  10. 002-java反编译工具jd-gui

    官网:https://github.com/java-decompiler 下载:https://github.com/java-decompiler/jd-gui/releases 使用: java ...