//自己方法只能拿到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. ASP.NET MVC 基础(01)

    [ASP.NET MVC ]系列文章大致会包含这样一些内容: 1.ASP.NET MVC 的一些高级知识点: 2.ASP.NET MVC 的一些最新技术: 3.ASP.NET MVC 网站安全方面的知 ...

  2. linux下如何不编译opencv的某些模块

    opencv非常庞大,有很多模块,但大部分情况我们可能只会用到三四个模块,此时如果还是直接cmake . & make,将会非常费时,尤其是部署时很麻烦. 所以需要去除掉一些不需要的模块,可参 ...

  3. nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

    启动nginx时报这个错 , 要么用root用户启动 , 要么在配置文件nginx.conf中将server下的listen端口改掉 , 因为在linux中端口号小于1024都是需要root权限的

  4. bootstrap-响应式图片、辅助类样式

    响应式图片: <div class="container"> <!-- img-responsive 响应式图片 --> <div class=&qu ...

  5. ubuntu 格式化U盘,并制作系统镜像

    1. 先要卸载U盘,使用如下命令: #umount /dev/sdb1 注意:/dev/后面的设备要根据你的实际情况而定,否则后面格式化,丢失数据!! 格式化U盘,并建立vfat文件系统 #mkfs. ...

  6. c# winform快捷键设置

    设置 Form 的 KeyPreview=true 然后在Form 的案件事件里判断按钮类型进行分别调用就可以了 private void Form1_KeyDown(object sender, K ...

  7. expdp和impdp的用法

    源地址:http://blog.chinaunix.net/uid-23622436-id-2394094.html

  8. DIV+CSS滑动门效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. 怎么查询局域网内全部电脑IP和mac地址..

    在局域网内查询在线主机的IP一般比较简单,但局域网内全部电脑的IP怎么才能够查到呢?查询到IP后我还要知道对方的一些详细信息(如MAC地址.电脑名称等)该怎么查询呢??? 工具/原料 Windows ...

  10. wait(0)

    public final synchronized void join(long millis) throws InterruptedException { long base = System.cu ...