1024 Palindromic Number
题意:
给出一个数N(N<=10^10),最多可操作K次(K<=100),每次操作为这个数和其反转之后的数相加,若得到的结果为回文数,则输出;若在K次迭代后仍然不是回文数,在输出第K次操作后的结果。
思路:
#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& a,const string& b)
{
string c;
;
;i>=;i--){
';
c=,temp%+')+c;
carry=temp/;
}
) c=,carry+')+c;
return c;
}
int main()
{
;
string str,tmp;
cin>>str>>k;
while(cnt<=k){
if(judge(str)){
cout<<str<<'\n'<<cnt<<'\n';
break;
}
if(cnt==k) tmp=str;
string r_str=str;
reverse(r_str.begin(),r_str.end());
str=add(str,r_str);
cnt++;
}
) cout<<tmp<<'\n'<<k<<'\n';
;
}
1024 Palindromic Number的更多相关文章
- PAT 甲级 1024 Palindromic Number
1024. Palindromic Number (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...
- 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 int_string转换 大整数相加
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- 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 1024 Palindromic Number[难]
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PTA (Advanced Level) 1024 Palindromic Number
Palindromic Number A number that will be the same when it is written forwards or backwards is known ...
- 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 ...
随机推荐
- neutron dhcp ha 实验
4个节点(controller, network,2 compute nodes) 1.0 on the network node 1.1 set –I ‘s/start] on/#start\ ...
- mysql 修改编码格式
下载了mysql的客户端,一般其默认的编码格式是gbk,为了方便后续使用,想要将其编码格式改为utf8. 这时候的方法是: 1.进入mysql的安装目录,找到my.ini文件. 2.以txt文件的格式 ...
- mysql学习笔记(Centos下rpm编译配置+远程访问)
新工作以来,博主感觉天天都很忙,博客已经好久没有写了 从昨天开始弄centos服务器中搭建mysql5.6,由于yum最新版本只有5.1的所以折腾到现在 首先看看是否已安装过其他版本的mysql [r ...
- Jexus部署Asp.Net Core项目
在之前的我的博客项目中,我将.net Core发布到Cent OS 上,使用的Nginx代理以及Supervisor进程守护,看过我的博客的童鞋,也会发现,这种方式比较麻烦,光命令行就看的头大,总共部 ...
- python线程、进程和协程
链接:http://www.jb51.net/article/88825.htm 引言 解释器环境:python3.5.1 我们都知道python网络编程的两大必学模块socket和socketser ...
- BusyIndicator using MVVM 忙碌状态指示器的的实现
ViewModel 视图模型 public abstract class ViewModelBase : INotifyPropertyChanged { private bool isbusy; p ...
- H5测试
H5是什么? H5的全称是HTML5,其实就是:移动端WEB页面. H5与原生 APP的区别: APP是使用原生系统内核的,相当于直接在系统上操作,是我们传统意义上的软件,更加稳定. H5的APP先得 ...
- split方法的使用
// 分隔竖线 String[] param = text.split("\\|"); //分隔问号 String name = singleResource.get(&quo ...
- kibana查询语法
单项term查询 例: 搜 Dahlen, Malone 字段field查询 field:value 例:city:Keyport, age:26 通配符 ? 匹配单个字符 例: H?b ...
- 剑指offer--26.顺时针打印矩阵
1,2,3,45,6,7,88,10,11,1213,14,15,16 每次输出第一行,然后删除第一行,逆时针旋转剩下的矩阵. ------------------------------------ ...