//自己方法只能拿到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. Yii 2.0 单文件上传

    先创建一个(UploadForm.php)模型层 <?phpnamespace app\models; use yii\base\Model;use yii\web\UploadedFile; ...

  2. java NIO经典实例

    服务端: Loader.java package net.chatroom.server; public class Loader { public static void main(String[] ...

  3. 使用gson-1.6.jar解析json

    package com.example.mars_2900_json01; import java.io.StringReader; import java.lang.reflect.Type; im ...

  4. Python开发专业工具推荐

    PyCharm,jetbrains公司出品,必是精品!! 版本:2016.3.1 下载:https://www.jetbrains.com/pycharm/download/#section=wind ...

  5. git简单使用和说明文件的书写

    一. git 简单使用 1.注册 https://github.com/ 2.初始化 配置 git config --global user.name "Your Name" gi ...

  6. PDF按模板出力,多个PDF合并

                 const string   TEMP_PREXFIX = "Temp_";                                       ...

  7. [经验总结]利用xlstproc处理XSLT的makefile

    转自:http://blog.csdn.net/thinkhy/article/details/5343739 # For XSLT PARSE = xsltproc SRC = main.xml S ...

  8. vb eof详解

    源地址:https://zhidao.baidu.com/question/87122186.html?qbl=relate_question_1&word=eof%20sql&ski ...

  9. Oracle中常用操作

    查看表中的字段名和类型 SELECT column_name,DATA_TYPE FROM cols WHERE TABLE_NAME=upper('tableName') ORDER BY COLU ...

  10. JAVA中继承时方法的重载(overload)与重写/覆写(override)

    JAVA继承时方法的重载(overload)与重写/覆写(override) 重载-Override 函数的方法参数个数或类型不一致,称为方法的重载. 从含义上说,只要求参数的个数或参数的类型不一致就 ...