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 ...
随机推荐
- Apache Tomcat 服务因 0 (0x0) 服务性错误而停止
操作系统:Windows Server 2003 SP2/win7 64JDK 版本为 6.0 update 6 安装在 D:\Java 目录下Tomcat 版本为 6.0.16 安装 D:\Tomc ...
- Mac环境下Android Studio配置Git以及最基本使用
Git是分布式版本管理工具,现在使用十分广泛,相对于SVN,GIT的使用更加方便,在离线环境下,仍然可以进行版本控制工作.且速度十分快.在Windows下,先需要自行安装Git程序,网址git-scm ...
- 数据挖掘算法Analysis Services-基于SQL Server的数据挖掘
数据挖掘算法(Analysis Services – 数据挖掘) data mining algorithm is a set of heuristics and calculations that ...
- 转载 IOS开发之---static变量
Objective-C 支持全局变量 主要有两种实现方式: (1)第一种和C/C++中的一样, 使用"extern"关键词: (2)另外一种就是使用单例实现. (比如我们经常会把一 ...
- Spring 依赖注入(一、注入方式)
Spring是一个依赖注入(控制反转)的框架,那么依赖注入(标控制反转)表现在那些地方了? 即:一个类中的属性(其他对象)不再需要手动new或者通过工厂方法进行创建,而是Spring容器在属性被使用的 ...
- UI- 基础控件零散知识点回归
1.frame\center\bounds 1> frame:能修改位置和尺寸 2> center:能修改位置 3> bounds:能修改尺寸(x\y一般都是0) 2.在.m中声明的 ...
- 【Codeforces】894D. Ralph And His Tour in Binary Country 思维+二分
题意 给定一棵$n$个节点完全二叉树,$m$次询问,每次询问从$a$节点到其它所有节点(包括自身)的距离$L$与给定$H_a$之差$H_a-L$大于$0$的值之和 对整棵树从叶子节点到父节点从上往下预 ...
- 字段值为NULL时的like注意事项
null like '%%'是有问题的 mysql中应该这样写COALESCE($ZU.mobile,'') like '%%' 或者 where IsNull([table].[column],'' ...
- 从无到有开发自己的Wordpress博客主题---局部模板的准备
毫无疑问,我们媒体页面都会有header和footer,这些用到的内容几乎是一样的. 从无到有,我们先不考虑后面可能用到的Search和Comment等的模板,后面的我会在文本最后面追加. 开始之前, ...
- LeNet-5网络结构及训练参数计算
经典神经网络诞生记: 1.LeNet,1998年 2.AlexNet,2012年 3.ZF-net,2013年 4.GoogleNet,2014年 5.VGG,2014年 6.ResNet,201 ...