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 ...
随机推荐
- 如何让Myeclipse已经关闭掉的项目不显示出来
一.打开Package Explorer视图,在它的右上角有一个向下的三角图标. 2.点击后选择Filters,在弹出的Filter配置窗口中选中"Closed Projects" ...
- BZOJ 1492 [NOI2007]货币兑换Cash:斜率优化dp + cdq分治
传送门 题意 初始时你有 $ s $ 元,接下来有 $ n $ 天. 在第 $ i $ 天,A券的价值为 $ A[i] $ ,B券的价值为 $ B[i] $ . 在第 $ i $ 天,你可以进行两种操 ...
- 通过Google Custom Search API 进行站内搜索
今天突然想把博客的搜索改为google的站内搜索,印象中google adsense中好像提高这个站内搜索的代码,但苦逼的是google adsense帐号一直审核不通过,所以只能通过google c ...
- Spring AOP(面向切面示例)
什么是AOP?基本概念切面(aspect):横切关注点被模块化的特殊对象.通知(advice):切面必须要完成的工作.切面中的每个方向称之为通知.通知是在切面对象中的.目标(target):被通知的对 ...
- react-router-dom: 重定向默认路由
<appLayout> <Switch> <Route path='/' exact render={()=> ( <Redirect to={this.ge ...
- L131
Fake, Low Quality Drugs Come at High CostAbout one in eight essential medicines in low- and middle-i ...
- java svnkit实现svn提交,更新等操作
官网:https://svnkit.com/ api:https://svnkit.com/javadoc/org/tmatesoft/svn/core/io/SVNRepository.html w ...
- 如何创建 Visual Studio 2017 RC 离线安装包
创建 Visual Studio 的离线安装计划 首先下载相应版本的可执行文件,例如:vs_community.exe.vs_enterprise.exe 或 vs_professional 在 cm ...
- Java一般要学多久?
其实学java一般要多久?因人而异,有些人资质好,头脑聪明几个月就能学会,有些人天生愚钝,理解能力差,不过勤能补拙,只是时间相对长点 要坚持住.不过java相对于C,C++java而言,java无疑简 ...
- Debian, Ubuntu, LinuxMint 安裝 MySQL 5.7, 5.6, 5.5
以下會示範在 Debian, Ubuntu 及 LinuxMint 分別安裝 MySQL 5.7, 5.6, 5.5 的方法. 首先按照需要的安裝的 MySQL 版本, 加入相應的 Repositor ...