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 ...
随机推荐
- php:二进制处理
直接上代码 <?php #字符串 #php中字符串就是二进制,不用特别转化 #方法1:直接把字符串当成二进制 $c = "ccc"; var_dump($c, bin2hex ...
- spring 基于XML和注解的两种事务配置方式
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- wl18xx module crash with "wlcore: ERROR ELP wakeup timeout!"
[ 111.322967] wlcore: ERROR ELP wakeup timeout![ 111.327636] ------------[ cut here ]------------[ 1 ...
- wpf应用程序 打印标签
新建一个wpf应用程序,Xaml如下: <Window x:Class="CreateBarCodeDemo.MainWindow" xmlns="http://s ...
- plsql 安装后database下拉没有东西
今天第一天上班我自己也有点紧张,但是问题还是有的: 今天来说一下问题,就是装了plsql竟然在database这一栏没有东西,我也是纠结了很久,感觉今天的任务也被拉下了. 其实这个问题在我以前装的时候 ...
- WPF Template模版之DataTemplate与ControlTemplate的关系和应用【二】
1. DataTemplate和ControlTemplate的关系 学习过DataTemplate和ControlTemplate,你应该已经体会到,控件只是数据的行为和载体,是个抽象的概念,至于它 ...
- runtime获取一个控件的所有属性
控件的有些属性API并没有开放,可以通过runtime查看: unsigned int count; Ivar *ivarList = class_copyIvarList([UITextField ...
- jquery 仿购物车的加减数量
<p>单价:3.95</p> <input id="min" name="" type="button" va ...
- 拓扑排序<反向拓扑+有向环的判断>
题目链接 #include <set> #include <map> #include <cmath> #include <queue> #includ ...
- (一)Python之猜数游戏
猜数游戏由简如深的编码学习过程: 3次机会: print('------------------我爱鱼C工作室------------------')count=0while count < 3 ...