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 ...
随机推荐
- 拓扑序+dp Codeforces Round #374 (Div. 2) C
http://codeforces.com/contest/721/problem/C 题目大意:给你有向路,每条路都有一个权值t,你从1走到n,最多花费不能超过T,问在T时间内最多能访问多少城市? ...
- kvm and virtualbox running side by side
http://dedoimedo.com/computers/kvm-virtualbox.html
- 上海赛趣-top.mainFrame.tabAddHandler方法详解
top.mainFrame.tabAddHandler("item"+Id,'项目:'+itemname,'<%=basePath%>bizitem/goEditIte ...
- sql server数据库中 INFORMATION_SCHEMA的用法
1.查询数据库的所有表: select * from INFORMATION_SCHEMA.TABLES 2.查询表名为xxx的所有列的信息 select * from INFORMATION_SCH ...
- 使用SQL Server Management Studio 创建作业备份数据库
在项目中,经常需要备份数据库,如果能做到只需点个按钮(“开始备份数据库”按钮),然后什么都不管,数据库就自动备份好了,或者服务器上的数据库隔一段时间自动备份一次,那该多好啊. Sql server 的 ...
- Linux标准目录
本文参考鸟哥的linux私房菜 /bin 获得最小的系统可操作性所需要的命令 /boot 内核和加载内核所需要的文件 /dev 终端.磁盘.调制解调器等的设备项 /etc 关键的启动文件和配置文件 / ...
- struts2中的<s:select>默认选项
//... public class SelectAction extends ActionSupport{ private List<String> searchEngine; priv ...
- SimplePath 使用心得
上图是 用SimplePath 做的 寻路,其中 三个 绿点 是 移动的 目标点,三个红点 是 角色移动,蓝色方块是阻挡物体. 这三个角色 移动 有三种 方式,1 随机移动2 按照 绿色小球点 移动 ...
- Linux学习 -- Shell基础 -- Bash变量
变量 默认是字符串型,数值型需要显示指定 等号两侧都不能有空格 单引号:原始字符串 双引号:保留转义 命令结果作为值:反引号 或 $() 环境变量一般用大写 自定义变量 变量定义 name=& ...
- Swift学习(1)
swif(1) println("Hello, world") 输出结果: Hello, world swift使用let来声明常量,使用var来声明变量 //变量 var myV ...