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 ...
随机推荐
- Spring 自定义标签配置
前景:经常使用一些依赖于Spring的组件时,发现可以通过自定义配置Spring的标签来实现插件的注入,例如数据库源的配置,Mybatis的配置等.那么这些Spring标签是如何自定义配置的?学习Sp ...
- ycsb两个阶段说明
ycsb有几个目录需要注意下: bin: - 目录下有个可执行的ycsb文件,是个python脚本,是用户操作的命令行接口.ycsb主逻辑是:解析命令行.设置java环境,加载java-libs,封 ...
- mysql 字段属性 与 排序
mysql中常见的数据类型:varchar(n).float.int(n).bigint(n).date.datetime.text 字段属性 默认值:DEFAULT '默认值' 非空:NOT NUL ...
- shell编程实例2
1.vim read_PERSON.sh 2. #!/bin/bash echo "What is your name?" read PERSON echo "Hell ...
- Linux下用c语言实现whereis.
简单的一个whereis的实现,代码如下: #include <stdio.h> #include <errno.h> #include <dirent.h> #i ...
- EL标签
1.EL的作用 jsp的核心语法: jsp表达式 <%=%>和 jsp脚本<% %>. 开发jsp的原则: 尽量在jsp页面中少写甚至不写java代码. 使用EL表达式替换掉 ...
- UI- 不易记知识点汇总
1.static: 所有的全局变量都是静态变量,而局部变量只有定义时加上类型修饰符static,才为局部静态变量. 静态变量并不是说其就不能改变值,不能改变值的量叫常量. 其拥有的值是可变的 ,而且它 ...
- Java中的深拷贝(深复制)和浅拷贝(浅复制)
深拷贝(深复制)和浅拷贝(浅复制)是两个比较通用的概念,尤其在C++语言中,若不弄懂,则会在delete的时候出问题,但是我们在这幸好用的是Java.虽然java自动管理对象的回收,但对于深拷贝(深复 ...
- SBT构建工具
SBT Simple Build Tool. A interactive build tool. install windows可直接到http://www.scala-sbt.org/0.13/do ...
- 旧书重温:0day2【7】堆溢出实验
相关文章我拍成了照片,放在了我的QQ空间不是做广告(一张一张的传太麻烦了)http://user.qzone.qq.com/252738331/photo/V10U5YUk2v0ol6/ 密码9 ...