#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. python基础之条件判断

    一.简单的if语句 举例 if money > 10000: print '我们去旅游吧' #左侧一定要有缩进,一般4个空格 print '请输入学生的考试成绩' score = print ( ...

  2. IOS中NSUserDefaults的用法

    NSUserDefaults适合存储轻量级本地数据,比如要保存用户登陆的用户名.密码,使用NSUserDefaults是首选.下次再登陆的时候就可以直接从NSUserDefaults里面读取上次登陆的 ...

  3. 把display 属性改为block样式变化问题

    可能的值 值 描述 none 此元素不会被显示. block 此元素将显示为块级元素,此元素前后会带有换行符. inline 默认.此元素会被显示为内联元素,元素前后没有换行符. inline-blo ...

  4. Domoticz 接入苹果的 HomeKit 实现 Siri 控制

    前言 接上次的折腾,这次尝试将 Domoticz 接入到苹果的 HomeKit,也就是在 iPhone 的 Siri 中可以语音控制.参考官方文档 步骤 安装 nodejs curl -sL http ...

  5. Android 数据库框架GreenDao实战使用

    1.添加记录(SQLite 增) 2.删除记录(SQLite 删) 3.修改记录(SQLite 改) 4.查询记录(SQLite 查) <1> DAO查询 <2>QueryBu ...

  6. Windows7下采用cygwin编译安装swoole扩展

    常用命令 查看cygwin当前的版本: cygcheck -c cygwin 检查所有安装软件的版本号:cygcheck -c 查看某一个软件安装的版本:cygcheck -c 软件名称 查看本地已经 ...

  7. pyhton学习,day1作业,用户名密码登录模块

    要求,通过用户名密码登录,登录错误3次,锁定用户名 # coding=utf-8 # Author: RyAn Bi import os, sys #调用系统自己的库 accounts_file = ...

  8. P3704 [SDOI2017]数字表格 (莫比乌斯反演)

    [题目链接] https://www.luogu.org/problemnew/show/P3704 [题解] https://www.luogu.org/blog/cjyyb/solution-p3 ...

  9. Codeforce-1106-D. Lunar New Year and a Wander(DFS遍历+vector存图+set)

    Lunar New Year is approaching, and Bob decides to take a wander in a nearby park. The park can be re ...

  10. PIE SDK过滤控制

    1.  功能简介 栅格数据前置过滤是在渲染之前对内存中的数据根据特定的规则进行处理,然后再进行数据渲染.本示例以定标为例进行示例代码编写. 定标(校准)是将遥感器所得的测量值变换为绝对亮度或变换为与地 ...