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 ...
随机推荐
- oracle添加sequence
CREATE SEQUENCE seq_tm_function INCREMENT BY 1 -- 每次加几个 START WITH 100000015 -- 从1开始计数 NOMAXVALUE -- ...
- s7-300 第一讲
s7-300的电源模块可选,s7-400必选
- 查看端口号他所占用的exe应用程序
- replication factor
http://www.tuicool.com/articles/RJbIBj 关于Hadoop中replication factor解惑 时间 2014-06-09 08:00:50 ITeye ...
- cakephp2.3.0 lib中的Model.php有一个bug
1. cakephp2.3.0 lib中的Model.php有一个bug, 加上 !empty($db->config['prefix']) 这个判断更好.有时候会少进行一次 new PDO() ...
- win10怎么启用网络发现,网络发现已关闭怎么办
脑和电脑之间传输文件的方式很多,其中一种就是使用局域网,在网络中我们的电脑应该可以被其他电脑发现是非常方便使用文件共享的,尤其是在使用家庭组网络的时候,那么win10里面怎么启用网络发现呢? 工具/原 ...
- 文件系统满的话(filesystem full),该如何处理。
#!/bin/bash function ergodic(){ ` do "/"$file ] then ergodic $"/"$file else loca ...
- 【floyd 多源最短路】 poj 1125
#include <stdio.h> #include <iostream> #include <memory.h> using namespace std; ][ ...
- JQuery Each循环遍历每个元素
输出每个 li 元素的文本: $("button").click(function(){ $("li").each(function(){ alert($(th ...
- JPA 系列教程2-单表操作
JPA Sun官方提出的Java持久化规范.它为Java开发人员提供了一种对象/关系映射工具来管理Java应用中的关系数据.他的出现主要是为了简化现有的持久化开发工作和整合ORM技术,结束现在Hibe ...