1136 A Delayed Palindrome
题意:略。
思路:大整数相加,回文数判断。对首次输入的数也要判断其是否是回文数,故这里用do...while,而不用while。
代码:
#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& s1,const string& s2)
{
string sum;
,temp,d;
;i>=;i--){
temp=carry+(s1[i]-');
d=temp%;
carry=temp/;
sum=,d+')+sum;
}
) sum=,carry+')+sum;
return sum;
}
int main()
{
string s1,s2;
cin>>s1;
;
do{
if(judge(s1)){
cout<<s1<<" is a palindromic number.\n";
break;
}
s2=s1;
reverse(s2.begin(),s2.end());
string sum=add(s1,s2);
cout<<s1<<" + "<<s2<<" = "<<sum<<"\n";
s1=sum;
}while(--cnt);
) cout<<"Not found in 10 iterations.\n";
;
}
1136 A Delayed Palindrome的更多相关文章
- PAT 1136 A Delayed Palindrome
1136 A Delayed Palindrome (20 分) Consider a positive integer N written in standard notation with k ...
- PAT 1136 A Delayed Palindrome[简单]
1136 A Delayed Palindrome (20 分) Consider a positive integer N written in standard notation with k+1 ...
- pat 1136 A Delayed Palindrome(20 分)
1136 A Delayed Palindrome(20 分) Consider a positive integer N written in standard notation with k+1 ...
- PAT甲级:1136 A Delayed Palindrome (20分)
PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...
- 1136 A Delayed Palindrome (20 分)
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
- 1136 A Delayed Palindrome (20 分)
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
- PAT1136:A Delayed Palindrome
1136. A Delayed Palindrome (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- A1136. Delayed Palindrome
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
- PAT A1136 A Delayed Palindrome (20 分)——回文,大整数
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
随机推荐
- JDBC插入性能优化对比
今天对Insert进行了性能测试,结果反差很大,平时都是单条插入,虽然性能要求没有那么高,但是突然在项目中,人家给定时间内完成,这就尴尬了. 优化数据库,优化服务器,优化代码,反正通过各种优化提高数据 ...
- Shell 运算符 if
Shell 支持多种运算符,包括: 算术运算符 原生bash不支持简单的数学运算,可以使用 expr,let 关系运算符 布尔运算符 字符串运算符 文件运算符 算术运算符 包括加减乘除,取余(%).赋 ...
- APP埋点:页面统计与事件统计该如何入手?
我们平时所说的埋点,可以大致分为两部分,一部分是统计APP页面访问情况,即页面统计:另外一部分是统计APP内的操作行为,及自定义事件统计. 一.页面统计 页面统计,可以统计应用内各个页面的访问次数(P ...
- poj2446
题解: 二分图匹配 看看是否能达到目标 代码: #include<cstdio> #include<cstring> #include<algorithm> #in ...
- LeetCode OJ:Insertion Sort List (插入排序链表)
Sort a linked list using insertion sort. 用插入排序来排序一个list,额, 我写的好麻烦啊, debug了好久,至少提交了5次...写吐了快,先贴代码,写的也 ...
- New Concept English three (38)
26w/m 45 Future historians will be in a unique position when they come to record the history of our ...
- 2017.11.13 python+ Jlink+EFM32 批量烧录
1 Add whl files to Python a. install the environment variable of path b . useing the CMD command : ...
- Tinymce group plugin
本文介绍一个tinymce插件,用来组合显示下拉的按钮.基于4.x,不兼容3.x. 以前 配置toolbar功能按钮 需要 toolbar1: "code undo red ...
- 在 Ubuntu 上搭建 Hadoop 分布式集群 Eclipse 开发环境
一直在忙Android FrameWork,终于闲了一点,利用空余时间研究了一下Hadoop,并且在自己和同事的电脑上搭建了分布式集群,现在更新一下blog,分享自己的成果. 一 .环境 1.操作系统 ...
- Arcgis andoid开发之应用百度地图接口实现精准定位与显示
怀着激动.兴奋的心情,在这个漫天柳絮的季节写下了这片博文,为什么呢,因为困扰我很久的一个技术性的问题得到了解决,发次博文,供大家参观.学习,同时,也以慰藉我长期困扰的心情,好了,废话不再,言归正传,看 ...