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 ...
随机推荐
- spring3: 内置Resource实现
4.2 内置Resource实现 4.2.1 ByteArrayResource ByteArrayResource代表byte[]数组资源,对于“getInputStream”操作将返回一个By ...
- ubuntu14.04搭建Hadoop2.9.0伪分布式环境
本文主要参考 给力星的博文——Hadoop安装教程_单机/伪分布式配置_Hadoop2.6.0/Ubuntu14.04 一些准备工作的基本步骤和步骤具体说明本文不再列出,文章中提到的“见参考”均指以上 ...
- pOJ-1061 exgcd求同余方程组
链接 就是求(m-n)*a+b*l=y-x, 类似于求解a*x+b*y=c,r=gcd(a,b),当c%r==0时有解,用exgcd求出a*x+b*y=gcd(a,b)的解,然后x*c/gcd(a,b ...
- 【mysql 】sql删除重复记录 You can't specify target table '表名' for update in FROM clause
用下面的语句就报语法出错: delete from tab_record where recordid not in (select min(c.recordid) as recordid from ...
- ipmitool 查看硬件信息
[root@75-6-25-yf-core ~]# cat /var/log/mcelog MCE 0HARDWARE ERROR. This is *NOT* a software problem! ...
- 慕课网:4-2—— 使用DB facade实现CURD (09:11)
public function test1() { //新增数据: /* $bool=DB::insert('insert into student(name,age) VALUES (?,?)', ...
- 启动代码之开iCache
1.什么是cache,有什么用 cache是一种内存,叫高速缓存.从容量来说:CPU < 寄存器 < cache < DDR从速度来说:CPU > 寄存器 > ca ...
- 基于Python实现的四则运算生成程序
Github项目地址:传送门 小组成员:黄晓彬(代码实现) 黄钰城(代码审查) 需求: 1. 使用 -n 参数控制生成题目的个数. 2. 使用 -r 参数控制题目中数值(自然数.真分数和真分数分母)的 ...
- Linux中查看各文件夹大小命令:du -h --max-depth=1
Linux中查看各文件夹大小命令:du -h --max-depth=1 du [-abcDhHklmsSx] [-L <符号连接>][-X <文件>][--block-siz ...
- sublime上配置markdown
等等等等 简书一个不错的教程:Sublime Text3的Markdown配置 补充说明:第一步可以直接找 Tools-->install package control. ^.^ ...