//自己方法只能拿到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的更多相关文章

  1. PAT1024. Palindromic Number (25)

    输入即为回文的情况要考虑 #include <iostream> #include <algorithm> //reverse using namespace std; str ...

  2. General Palindromic Number (进制)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  3. Palindromic Number (还是大数)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  4. [ACM] ZOJ 3816 Generalized Palindromic Number (DFS,暴力枚举)

    Generalized Palindromic Number Time Limit: 2 Seconds      Memory Limit: 65536 KB A number that will ...

  5. PAT1019:General Palindromic Number

    1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. A1019. General Palindromic Number

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

随机推荐

  1. Spark读写Hbase中的数据

    def main(args: Array[String]) { val sparkConf = new SparkConf().setMaster("local").setAppN ...

  2. kuangbin RMQ

    这是kuangbin的RMQ,一维的,代码很简洁,附上: //kuangbin templet(查询最大值) 一维 //若想查最小,看提示更改 + ; ];//第二维是范围,即2^20约等于100万 ...

  3. linux 挂载(转载)

    From:http://forum.ubuntu.org.cn/viewtopic.php?t=257333 用linux,就一定要用linux的方式去思维.嗯,说的容易做起来难.我的D盘哪去了?恐怕 ...

  4. 异步task处理

    public async Task<Customers> GetCustomers() { return await Service.GetCustomersAsync(); } publ ...

  5. windows service的继承类ServiceBase

    https://msdn.microsoft.com/zh-cn/library/system.serviceprocess.servicebase.exitcode(v=vs.80).aspx 在停 ...

  6. 支付宝&腾讯的OpenID之路

         10年前上网很简单,那时我只用记住三个账号:QQ.21cn邮箱和中国联众.10年后的今天,应用或服务层次不穷:盛大网游.淘宝.豆瓣.人人.微博……太多的账号和密码我已经没办法记住.如果有一个 ...

  7. [ActionScript 3.0] AS3 对XML的操作,创建、删除、增加节点方法

    package { import flash.display.Sprite; /** * @author:Frost.Yen * @E-mail:871979853@qq.com * @create: ...

  8. [ActionScript 3.0] AS3 绘制12面体

    package { import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; im ...

  9. position中多次用到了relative和absolute,能不能具体介绍一下这两者的区别?

    position中多次用到了relative和absolute,能不能具体介绍一下这两者的区别? 一个是相对定位,一个是绝对定位. absolute生成绝对定位的元素,相对于 static 定位以外的 ...

  10. Delphi 线程的处理

    http://www.cnblogs.com/doit8791/archive/2012/05/16/2502671.html