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 ...
随机推荐
- memcached应用场景(转)
memcached最吸引人的地方主要在于它的分布式.分布式对于互联网应用来讲,按照用途基本上可划分为三种方式:分布式计算.分布式存储和两者兼而有之.memcached是分布式存储的一种.我们常见的分 ...
- Laravel中URL,ACTION,ROUTE区别
创建路由如下所示: Route::get('articles',['uses'=>'ArticlesController@index','as'=>'articles.index']); ...
- lable标签透明
方法1: pictureBox1.Controls.Add(lable1); //或 this.label1.Parent=pictureBox1; lable1.BackColor=Col ...
- 20145305 《Java程序设计》实验一
实验名称 实现凯撒密码,并进行测试. 实验内容 它是一种代换密码.据说凯撒是率先使用加密函的古代将领之一,因此这种加密方法被称为恺撒密码. 凯撒密码作为一种最为古老的对称加密体制,在古罗马的时候都已经 ...
- Android Studio 系列教程(转载)
史上最详细的Android Studio系列教程一--下载和安装:http://segmentfault.com/a/1190000002401964史上最详细的Android Studio系列教程二 ...
- linux内核设计与实现--从内核出发
linux内核有两种版本:稳定的和处于开发中的. linux通过一种简单的命名机制来区分稳定的和处于开发中的内核,使用3个或者4个“.”分割的数字来代表不同内核版本. 如:2.6.26.1:第一个数字 ...
- [Flex] PopUpButton系列——CornerRadius的运用
<?xml version="1.0" encoding="utf-8"?><!--设置主按钮圆角半径 PopUpButtonCornerRa ...
- JDK环境变量中dt.jar、tools.jar等变量值的作用
变量名:CLASSPATH 变量值:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar; tools.jar: 工具类 库,它跟我们程序中用到的 基础 ...
- GridView内容<br />换行
if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[].Text = Server.HtmlDecode(e.Row.Cell ...
- Angularjs过滤器的开发.
先上代码. <!DOCTYPE html> <html ng-app="FilterModule"> <head lang="en" ...