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 ...
随机推荐
- Unity 的ICallHander在C#项目中实现注入
项目包引用: Install-Package Unity.Interception 创建项目的接口和其实类: public interface ICalculator { double Calcula ...
- User.java 实体类 带 数据库字段模板
package com.tgb.web.controller.entity; import javax.persistence.Column; import javax.persistence.Ent ...
- textarea内容太多, 鼠标点击全部显示
strRight+="<td bordercolor='#DEDEDE' width='500px' height='50'><div title='"+data ...
- linux查看文件及文件夹的大小
最近发现服务器的磁盘容量使用率超过了90%,所以有必要查看是哪个文件占用了太多的空间, 服务器系统:CentOS6.5 df -h #查看磁盘使用情况,步骤1 cd / #切换到根目录, 步骤2 du ...
- jetty作为内嵌服务器自启动
为了完成web工程的测试,最近内嵌jetty也要搞起来.第一次搞还是挺焦头烂额的.直接上成果: package com.test.action; import java.io.File; import ...
- linux的学习系列 4---文件权限和访问模式
为了更加安全的存储文件,Linux为不同的文件赋予了不同的权限,每个文件都拥有下面三种权限: 所有者权限:文件所有者能够进行的操作 组权限:文件所属用户组能够进行的操作 外部权限(其他权限):其他用户 ...
- POJ 2082Lost Cows<>
题意: 给出一个序列a[1....n],a[i]代表在0....i-1中比a[i]小的个数. 求出这个序列. 思路: 1:暴力. #include<cstdio> #include< ...
- Swift 使用Extension 场景 浅析
别人一看到我的 Swift 代码,立刻就会问我为什么如此频繁的使用 extension.这是前几天在我写的另一篇文章中收到的评论: 我大量使用 extension 的主要目的是为了提高代码可读性.以下 ...
- Android ViewDragHelper完全解析 自定义ViewGroup神器
Android ViewDragHelper完全解析 自定义ViewGroup神器 转载请标明出处: http://blog.csdn.net/lmj623565791/article/detai ...
- 基础-session,cookie,jsp,EL,JSTL
会话可以简单理解为:用户打开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话. kookie是在服务器端创建的,返回给浏览器,在浏览器的目录中保存了,下一次 ...