PAT1024. Palindromic Number
//自己方法只能拿到15分后边老是又过不了的点,用了网上别人的方法,用库函数的翻转reverse(),参数分别是起始位置个结束位置,注意只能在原存储空间翻转,即比较对称时,再生请一个空间,将原来字符串复制进来并翻转,然后 用字符串比较,直接得出是否对成(字符串比较按字典序比较与strcmp相同)
//string 库函数操作insert(插入位置,插入元素),算是熟悉下string的函数吧
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string add(string s1,string s2)
{
int c=0;
string ans="";
int len1=s1.length();
int sum,i;
for(i=len1-1;i>=0;i--)
{
sum=s1[i]-'0'+s2[i]-'0'+c;
ans.insert(ans.begin(),sum%10+'0');
c=sum/10;
}
if(c)ans.insert(ans.begin(),c+'0');
return ans;
}
int main()
{
string s,rs;
int k,cnt=0;
cin>>s;
cin>>k;
while(cnt<k)
{
rs=s;
reverse(rs.begin(),rs.end());
if(s==rs)break;
else
{
s=add(s,rs);
cnt++;
}
}
cout<<s<<endl;
cout<<cnt<<endl;
return 0;
}
PAT1024. Palindromic Number的更多相关文章
- PAT1024. Palindromic Number (25)
输入即为回文的情况要考虑 #include <iostream> #include <algorithm> //reverse using namespace std; str ...
- General Palindromic Number (进制)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- Palindromic Number (还是大数)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- [ACM] ZOJ 3816 Generalized Palindromic Number (DFS,暴力枚举)
Generalized Palindromic Number Time Limit: 2 Seconds Memory Limit: 65536 KB A number that will ...
- PAT1019:General Palindromic Number
1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...
- 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 ...
- PAT A1024 Palindromic Number (25 分)——回文,大整数
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT A1019 General Palindromic Number (20 分)——回文,进制转换
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- A1019. General Palindromic Number
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
随机推荐
- OAF_EO系列5 - Update详解和实现(案例)
2014-06-14 Created By BaoXinjian
- 实现从sql server存取二进制图片
转:http://www.cnblogs.com/jeffwongishandsome/archive/2009/08/27/1554440.html 1.存取图片(1).将图片文件转换为二进制并直接 ...
- Json--Android中数据文件解析(Json解析--从服务器端获取数据并且解析,显示在客户端上面)
前面学习过了使用SAX解析XML数据(点击进入:SAX解析XML数据),今天学习Json解析: 首先说一下Json数据的最基本的特点,Json数据是一系列的键值对的集合,和XML数据来比,Json数据 ...
- JAVA 类中方法参数与返回值
无参无返回值的方法,用public void 方法名,来声明: 有参无返回值的方法,用public void 方法名,来声明: 有参有返回值的方法,用public int 方法名(int i,int ...
- Cassandra安装及其简单试用
官方主页:http://cassandra.apache.org/ 简介: The Apache Cassandra Project develops a highly scalable second ...
- 庭审全程文字实录 z
备受关注的深圳快播公司涉黄案两日来在北京市海淀法院开庭审理,快播CEO王欣(微博).事业部总经理吴铭.事业部副总经理张克东.事业部副总经理兼市场部总监牛文举出庭接受审理. 面对传播淫秽物品牟利罪的指控 ...
- iOS使用AVFoundation实现二维码扫描
原文:http://strivingboy.github.io/blog/2014/11/08/scan-qrcode/ 关于二维码扫描有不少优秀第三方库如: ZBar SDK 里面有详细的文档,相应 ...
- 使用Jenkins搭建持续集成服务
1. 什么是持续集成 持续集成 (Continuous Integration, 简称 CI) 是软件工程中的一种实践, 用于将开发人员不同阶段的工作成果集成起来, 通常一天之中会进行多次. 持续集成 ...
- 批量修改java文件的包名
需求:我复制进批量的java文件,但是包名需要用现在创建的包名 导入进来时,由于包名不一致会报错 解决办法,点击包名鼠标右键>Refactor>Rename 结果如下ok:
- java socket通讯(二)处理多个客户端连接
通过java socket通讯(一) 入门示例,就可以实现服务端和客户端的socket通讯,但是上一个例子只能实现一个服务端和一个客户端之间的通讯,如果有多个客户端连接服务端,则需要通过多线程技术来实 ...