#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm> using namespace std; void print(vector<char> &num) {
int len = num.size();
bool value_begin = false;
for (int i=; i<len; i++) {
if (!value_begin && num[i] == ) continue; // skip leading zeros;
value_begin = true;
printf("%d", num[i]);
}
if (!value_begin) { // totally zero
printf("");
}
} vector<char> num2vec(long long num) {
vector<char> ret; while (num) {
ret.push_back(num % );
num /= ;
}
reverse(ret.begin(), ret.end());
return ret;
} vector<char> add(vector<char> &a, vector<char> &b) {
vector<char> ret;
int alen = a.size();
int blen = b.size();
int carry= ;
while (alen > && blen > ) {
int d = carry + a[--alen] + b[--blen];
carry = d / ;
d = d % ;
ret.push_back(d);
} while (alen > ) {
int d = carry + a[--alen];
carry = d / ;
d = d % ;
ret.push_back(d);
}
while (blen > ) {
int d = carry + b[--blen];
carry = d / ;
d = d % ;
ret.push_back(d);
}
if (carry) ret.push_back();
reverse(ret.begin(), ret.end());
return ret;
} vector<char> pal(vector<char> &num) {
vector<char> ret = num;
reverse(ret.begin(), ret.end());
return ret;
} bool is_pal(vector<char> &num) {
int len = num.size();
int p = , q = len - ;
while (p < q) {
if (num[p] != num[q]) break;
++p, --q;
}
return p >= q;
} int main() {
long long n = , k = , i = ;
scanf("%ld%ld", &n, &k);
vector<char> num = num2vec(n);
for (i=; i<k; i++) {
if (is_pal(num)) {
break;
}
vector<char> pnum = pal(num);
vector<char> tnum = add(pnum, num);
swap(num, tnum);
}
print(num);
printf("\n%d", i);
return ;
}

要注意数值范围,非常喜欢在这种地方搞你一下

PAT 1024 Palindromic Number的更多相关文章

  1. PAT 1024 Palindromic Number[难]

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  2. PAT 甲级 1024 Palindromic Number

    1024. Palindromic Number (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

  3. PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)

    1024 Palindromic Number (25 分)   A number that will be the same when it is written forwards or backw ...

  4. 【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 ...

  5. 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 ...

  6. 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 ...

  7. 1024 Palindromic Number int_string转换 大整数相加

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  8. PAT A1024 Palindromic Number (25 分)——回文,大整数

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  9. 1024. Palindromic Number (25)

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

随机推荐

  1. [Swift实际操作]九、完整实例-(3)创建和安装开发证书、发布证书及开发证书配置文件、发布证书配置文件

    本文将为你演示,如何创建开发证书和发布证书,以及其他辅助内容.首先打开浏览器,进入[苹果开发者网站]输入[Apple ID]和[密码],点击登录按钮,进入开发者管理后台. 点击左侧的[Membersh ...

  2. 中国版Azure 文件服务

    中国版Azure 文件服务预览版在2015年1月13日已经上线,文件存储使用标准SMB 2.1协议为应用程序提供共享存储. 当我们的虚拟机连接到文件共享后就可以像使用本地共享文件夹一样来读取和写入文件 ...

  3. 你必须知道的----C语言笔试面试中经典易错的一些知识点(持续更新)

    1. 关于二级指针的解析和引用 1.1  二级指针意义  二级指针存放的是一级指针的地址    Ex: Int a = ; Int *p = &a; Int **q = &p; 1.2 ...

  4. SDUT OJ 数据结构实验之二叉树八:(中序后序)求二叉树的深度

    数据结构实验之二叉树八:(中序后序)求二叉树的深度 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Probl ...

  5. Ntrip协议使用流程及服务器实现架构

    Ntrip协议 在RTK接收机中,有多种方式获取到差分数据:电台.挂外串口.网络等.其中网络方式适合在有网络基准站的地区,省掉携带多一台RTK接收机来完成工作. CORS是网络基准站,通过网络收发GP ...

  6. 6. 重点来啦,pytest的各种装饰圈fixtures

    pytest中,fixture的目的是什么 为可靠的和可重复执行的测试提供固定的基线.(可以理解为测试的固定配置,使不同范围的测试都能够获得统一的配置.) fixture提供了区别于传统单元测试(se ...

  7. $(xx).load()同步

    这是由于 load 加载时并不是同步的,是异步的.在你点击执行 load 时,在load异步处理还没完成时,当然,就是调出了原来 #show 的内容了,当你第二次当点击时,原来第一次点击的 load异 ...

  8. 洛谷 P2286 [HNOI2004]宠物收养场

    题目描述 凡凡开了一间宠物收养场.收养场提供两种服务:收养被主人遗弃的宠物和让新的主人领养这些宠物. 每个领养者都希望领养到自己满意的宠物,凡凡根据领养者的要求通过他自己发明的一个特殊的公式,得出该领 ...

  9. CentOS中源码编译安装Nginx

    1.从官网通过wget命令将Nginx源码包下载到Linux上 ​ Nginx下载页面:http://nginx.org/en/download.html 2.在Linux上安装需要依赖的环境 yum ...

  10. UESTC - 1692 注意DP顺序

    #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...