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

 #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. X明X源面试题《一》

    本文转载自zhangkang 今天去明源面试,面试题目如下 1 有两张表 A 学生表 ID          Name          age 1           李1             ...

  2. [HAOI2012]Road

    2750: [HAOI2012]Road Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 728  Solved: 349[Submit][Status ...

  3. Ants(二分图最佳完美匹配)

    Ants Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6904   Accepted: 2164   Special Ju ...

  4. Springboot 1.5.x版本上读取自定义配置文件问题

    原来的解决方案: 现在1.5.x以后取消了location地址 1.5以后解决方案:

  5. make tree install 目录树状结构工具安装

    http://futeng.iteye.com/blog/2071867 http://zhou123.blog.51cto.com/4355617/1196415 wget ftp://mama.i ...

  6. POSIX相关概念

    POSIX 表示可移植操作系统接口(Portable Operating System Interface ,缩写为 POSIX),POSIX标准定义了操作系统应该为应用程序提供的接口标准,是IEEE ...

  7. phonegap file api

    https://github.com/chrisben/imgcache.js/tree/master/examples 1.FILE API file api最大的两个功能是download和upl ...

  8. 【Network】DDoS攻击防御

    DDoS(Distributed Denial of Service,分布式拒绝服务)攻击的主要目的是让指定目标无法提供正常服务,甚至从互联网上消失,是目前最强大,最难防御的攻击之一. 按照发起的方式 ...

  9. sql获取该周的开始结束日期

    mssql函数 IF EXISTS ( SELECT 1 FROM sysobjects WHERE name = 'fn_GetWeekDate') DROP FUNCTION fn_GetWeek ...

  10. MySQL数据库(6)_用户操作与权限管理、视图、存储过程、触发器、基本函数

    用户操作与权限管理 MySQL用户操作 创建用户 方法一: CREATE USER语句创建 CREATE USER "用户名"@"IP地址" IDENTIFIE ...