PAT1024. Palindromic Number (25)
输入即为回文的情况要考虑
#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)的更多相关文章
- PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)
1024 Palindromic Number (25 分) A number that will be the same when it is written forwards or backw ...
- 1024. Palindromic Number (25)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- 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 ...
- 【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 ...
- 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 ...
- 1024 Palindromic Number (25 分)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT1024. Palindromic Number
//自己方法只能拿到15分后边老是又过不了的点,用了网上别人的方法,用库函数的翻转reverse(),参数分别是起始位置个结束位置,注意只能在原存储空间翻转,即比较对称时,再生请一个空间,将原来字符串 ...
- PAT (Advanced Level) 1024. Palindromic Number (25)
手动模拟加法高精度. 注意:如果输入数字的就是回文,这个时候输出0步. #include<iostream> #include<cstring> #include<cma ...
- PAT甲题题解-1024. Palindromic Number (25)-大数运算
大数据加法给一个数num和最大迭代数k每次num=num+num的倒序,判断此时的num是否是回文数字,是则输出此时的数字和迭代次数如果k次结束还没找到回文数字,输出此时的数字和k 如果num一开始是 ...
随机推荐
- bsd socket 网络通讯必备工具类
传输数据的时候都要带上包头,包头有简单的又复杂的,简单的只要能指明数据的长度就够了. 这里我写了一个工具类,可以方便地将整型的数据长度转换为长度为 4 的字节数组. 另一方面,可以方便的将长度为 4 ...
- easy 正则表达式验证 封装
基于EasyUI ValidateBox 的表单验证,可以直接写正则表达式. 在页面加载时执行下面代码 if ($.fn.form) { $.extend($.fn.validatebox.defau ...
- MongoDB实践-自定义ASP.NET Session Store
Session由来 由于HTTP协议是无状态的,客户端与服务器端进行“请求-响应”操作后,建立的连接就释放了,服务器端根本不知道刚才是哪个客户端访问的.但是有些场景是需要知道客户端的状态的,最典型的就 ...
- Docker selinux
编辑/etc/sysconfig/docker文件,把OPTIONS='--selinux-enabled'的--selinux-enabled注释掉,也可以通过这个错误. 最大的问题就是Linux的 ...
- ztree的异步加载
js中代码为: //参数设置: var setting = { async: { enable: true, url:"<%=path%>/role/getTreeData ...
- ORACLE中的MERGE语法使用记录
项目中使用到了Oracle的MERGE INTO语句,在这里简单记录下使用方法 使用场景如下: 存在对一张数据量很大的表,你需要对里面的大量数据进行更新,如果数据不存在,就进行插入的操作. 常规想到的 ...
- jq cookie
//$.cookie("xx");//读取xx的值 //$.cookie("xx","123");//设置xx的值为123 //$.cook ...
- RemoveDuplicatesfromSortedArray
Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...
- PyNN standard model(转)
PyNN standard model 转自http://blog.csdn.net/qq_34886403/article/details/76667477
- PyQt4 颜色选择,字体选择代码
# -*- coding: utf-8 -*- """ ------------------------------------------------- File Na ...