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 ...
随机推荐
- node-wechat 微信推送消息
https://github.com/nswbmw/node-wechat/blob/master/index.js
- respond.js第六行 SCRIPT5: 拒绝访问。跨域问题
问题描述:respond.js第六行 SCRIPT5: 拒绝访问.昨天为学弟学妹讲bootstrap,说到对ie78的兼容问题,解决办法中有引入html5shiv.js和respond.js两个文件夹 ...
- 【scala】集合框架
- 【2018年全国多校算法寒假训练营练习比赛(第四场)-A】石油采集(匈牙利算法)
试题链接:https://www.nowcoder.com/acm/contest/76/A [思路] 每个‘#’的右边和下边如果也是‘#’说明这两个点构成通路,以此重构一幅图,然后找二分图的最大匹配 ...
- CSS:Tutorial one
1.Three Ways to Insert CSS External style sheet Internal style sheet Inline style External Style She ...
- jsp中解决乱码问题
解决中文乱码 a) 第一种: String name=new String(name.getBytes("ISO-8859-1"),"UTF-8"); b) 第 ...
- QT画图
if (0) { QApplication a(argv, args); QGraphicsScene scene; scene.setSceneRect(-300,-300,600,600); sc ...
- 使用Metasploit收集邮箱信息
Metasploit提供了很多辅助的模块,非常实用.今天介绍一个叫search_email_collector的模块,它的功能是查找搜索引擎(google.bing.yahoo),收集和某个域名有关的 ...
- [转载] FFMPEG视音频编解码零基础学习方法
在CSDN上的这一段日子,接触到了很多同行业的人,尤其是使用FFMPEG进行视音频编解码的人,有的已经是有多年经验的“大神”,有的是刚开始学习的初学者.在和大家探讨的过程中,我忽然发现了一个问题:在“ ...
- NOI 2018 你的名字
因为机房里的小伙伴都在看<你的名字.>而我不想看 所以来写了这道题... 给一个 $S$ 串,$q$ 次询问,每次一个 $T$ 串,问 $T$ 有多少没在 $S[l,r]$ 中以子串形式出 ...