PAT (Advanced Level) 1024. Palindromic Number (25)
手动模拟加法高精度。
注意:如果输入数字的就是回文,这个时候输出0步。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<vector>
using namespace std; char s[],t[],c[];
int tep; void f(char *x)
{
int len=strlen(x);
for(int i=; i<len/; i++) swap(x[i],x[len-i-]);
} bool work()
{
strcpy(t,s);
f(t);
int k=;
int len=strlen(s);
int num1,num2; memset(c,,sizeof c); for(int i=; i<=len; i++)
{
if(s[i]==) num1=num2=;
else num1=s[i]-'',num2=t[i]-'';
c[i]=(num1+num2+k)%+'';
k=(num1+num2+k)/;
}
if(c[len]=='') c[len]=;
f(c); int lenc=strlen(c);
for(int i=; i<lenc; i++)
if(c[i]!=c[lenc-i-]) return ;
return ;
} int main()
{
memset(s,,sizeof s);
memset(t,,sizeof t); scanf("%s",s);
scanf("%d",&tep); int sz=strlen(s); bool fail=;
for(int i=; i<sz; i++)
if(s[i]!=s[sz-i-]) fail=;
if(fail==)
{
printf("%s\n",s);
printf("%d\n",);
}
else
{
bool flag=; for(int i=; i<=tep; i++)
{
if(work())
{
printf("%s\n",c);
printf("%d\n",i);
flag=;
break;
}
strcpy(s,c);
} if(flag==)
{
printf("%s\n",c);
printf("%d\n",tep);
}
}
return ;
}
PAT (Advanced Level) 1024. Palindromic Number (25)的更多相关文章
- PTA (Advanced Level) 1024 Palindromic Number
Palindromic Number A number that will be the same when it is written forwards or backwards is known ...
- 【PAT甲级】1024 Palindromic Number (25 分)
题意: 输入两个正整数N和K(N<=1e10,k<=100),求K次内N和N的反置相加能否得到一个回文数,输出这个数和最小的操作次数. trick: 1e10的数字相加100次可能达到1e ...
- PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)
1024 Palindromic Number (25 分) A number that will be the same when it is written forwards or backw ...
- PAT Advanced 1024 Palindromic Number (25) [数学问题-⼤整数相加]
题目 A number that will be the same when it is written forwards or backwards is known as a Palindromic ...
- 【PAT】1024. Palindromic Number (25)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- 1024 Palindromic Number (25)(25 point(s))
problem A number that will be the same when it is written forwards or backwards is known as a Palind ...
- 1024. Palindromic Number (25)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT Advanced 1019 General Palindromic Number (20 分)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- 1024 Palindromic Number (25 分)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
随机推荐
- iOS 的 APP 如何适应 iPhone 5s/6/6Plus 三种屏幕的尺寸?
初代iPhone 2007年,初代iPhone发布,屏幕的宽高是 320 x 480 像素.下文也是按照宽度,高度的顺序排列.这个分辨率一直到iPhone 3GS也保持不变. 那时编写iOS的App( ...
- subversion SVN global ignore pattern
*.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo *.rej *~ #*# .#* .*.swp .DS_Store */bin */ ...
- NTP服务器时间同步
CentOS 配置服务器NTP同步 1 查看是否安装 rpm -aq | grep ntp 2 安装 yum -y install ntp 3 配置 /etc/ntp.conf restrict 访问 ...
- 得到root,并且获取密码
第一次使用ubuntu的时候 先使用这个命令 sudo passwd root 然后就可以改密码了
- 使用jquery的js的页面实现例子
var validate;var nodeId="";var modifyappId=""; addExportTaskURL = ctx + "/x ...
- ibatis 自动生成map,bean,dao
1.下载 AbatorForEclipse1.1.0 地址:http://download.csdn.net/detail/fym548/9426877 点击Archive按钮选择下载的,然后重启My ...
- BCDBOOT命令参数介绍
BCDboot 命令行选项 更新时间: 2013年10月 应用到: Windows 8, Windows 8.1, Windows Server 2012, Windows Server 2012 R ...
- java断点
第一步: 用firefox运行程序,当点击保存,提示保存失败后,启动firebug 通过请求找到addNew.ezt出现错误,在eztnews.xml里通过ctrl+F查找找到请求执行的类和方法 找到 ...
- 线程访问 DevExpress控件异常时 解决方法
Control.CheckForIllegalCrossThreadCalls = false; DevExpress.Data.CurrencyDataController.DisableThrea ...
- Python基础学习8---list列表的操作
a_list = ['hello','world',1,'shanghai',3.99] #列表添加操作的4种方法 #1. 通过+ 字符来拼接 a_list = a_list + [1,'wuhan' ...