pat 1136 A Delayed Palindrome(20 分)
1136 A Delayed Palindrome(20 分)
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 with 0≤ai<10 for all i and ak>0. Then N is palindromic if and only if ai=ak−i for all i. Zero is written 0 and is also palindromic by definition.
Non-palindromic numbers can be paired with palindromic ones via a series of operations. First, the non-palindromic number is reversed and the result is added to the original number. If the result is not a palindromic number, this is repeated until it gives a palindromic number. Such number is called a delayed palindrome. (Quoted from https://en.wikipedia.org/wiki/Palindromic_number )
Given any positive integer, you are supposed to find its paired palindromic number.
Input Specification:
Each input file contains one test case which gives a positive integer no more than 1000 digits.
Output Specification:
For each test case, print line by line the process of finding the palindromic number. The format of each line is the following:
A + B = C
where A
is the original number, B
is the reversed A
, and C
is their sum. A
starts being the input number, and this process ends until C
becomes a palindromic number -- in this case we print in the last line C is a palindromic number.
; or if a palindromic number cannot be found in 10 iterations, print Not found in 10 iterations.
instead.
Sample Input 1:
97152
Sample Output 1:
97152 + 25179 = 122331
122331 + 133221 = 255552
255552 is a palindromic number.
Sample Input 2:
196
Sample Output 2:
196 + 691 = 887
887 + 788 = 1675
1675 + 5761 = 7436
7436 + 6347 = 13783
13783 + 38731 = 52514
52514 + 41525 = 94039
94039 + 93049 = 187088
187088 + 880781 = 1067869
1067869 + 9687601 = 10755470
10755470 + 07455701 = 18211171
Not found in 10 iterations.
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define wzf ((1 + sqrt(5.0)) / 2.0)
#define INF 0x3f3f3f3f
#define LL long long
using namespace std; const int MAXN = 2e3 + ; char A[MAXN], B[MAXN], C[MAXN]; void calcB()
{
int len = strlen(A), a = len - , b = ;
for (a ,b ; b < len; ++ b, -- a)
B[b] = A[a];
} void calcC()
{
int len1 = strlen(A), len = len1, b = ;
int temp[MAXN];
for (int i = , j = len1 - ; i < len; ++ i, -- j)
{
if (j != -) b += int(A[j] - '') + int(B[j] - '');
temp[i] = b % ;
b /= ;
if (i == len - && b > ) ++ len;
} for (int i = , j = len - ; i < len; ++ i, -- j)
C[i] = char ('' + temp[j]);
} int main()
{
scanf("%s", &A);
int len = strlen(A), a = len - , b = ;
for (a ,b ; b < len; ++ b, -- a)
B[b] = A[a];
for (int i = ; ; ++ i)
{
if (i == )
{
printf("Not found in 10 iterations.\n");
break;
}
calcB();
if (strcmp(A, B) == )
{
printf("%s is a palindromic number.\n", A);
break;
}
calcC();
printf("%s + %s = %s\n", A, B, C);
strcpy(A, C);
}
return ;
}
pat 1136 A Delayed Palindrome(20 分)的更多相关文章
- PAT甲级:1136 A Delayed Palindrome (20分)
PAT甲级:1136 A Delayed Palindrome (20分) 题干 Look-and-say sequence is a sequence of integers as the foll ...
- PAT 1136 A Delayed Palindrome
1136 A Delayed Palindrome (20 分) Consider a positive integer N written in standard notation with k ...
- PAT 1136 A Delayed Palindrome[简单]
1136 A Delayed Palindrome (20 分) Consider a positive integer N written in standard notation with k+1 ...
- PAT乙级:1088 三人行 (20分)
PAT乙级:1088 三人行 (20分) 题干 子曰:"三人行,必有我师焉.择其善者而从之,其不善者而改之." 本题给定甲.乙.丙三个人的能力值关系为:甲的能力值确定是 2 位正整 ...
- PAT乙级:1064 朋友数 (20分)
PAT乙级:1064 朋友数 (20分) 题干 如果两个整数各位数字的和是一样的,则被称为是"朋友数",而那个公共的和就是它们的"朋友证号".例如 123 和 ...
- PAT A1136 A Delayed Palindrome (20 分)——回文,大整数
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
- 1136 A Delayed Palindrome (20 分)
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
- 1136 A Delayed Palindrome (20 分)
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
随机推荐
- 微信小程序之页面引用utils中的js文件
/* 只可使用相对路径 */const utils = require('../../../utils/util.js') Page({})
- java学习1-初始java程序
# 第一个简单示例 public class Hello { public static void main(String[] args) { System.out.println("Hel ...
- vue实现简易计算器
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- CSP考场Emacs使用指南[原创]
前言: 据说,CSP考试,之后不再支持windows了呢. windows用户真得劲! 那用什么系统? Ubuntu上场了 Ubuntu编译指南 进入Ubuntu系统,在你想存的文件夹中新建一个空白文 ...
- 微信小程序开发注意事项(优化项)
最近公司有一个小程序开发项目,自己也自学了不少,有一些开发小心得,记录在这里. 小程序开发中注意: 1,setData 小程序视图层和逻辑层在两个独立的模块,并不具备数据直接传递的,setData相当 ...
- 一、如何使用postman做接口测试笔记一
一.什么是接口测试 前端(客户端):Android.ios.web 后端(服务端):java.js.css 接口测试即功能测试,接口是用来连接客户端和服务端的,一般接口返回的数据都是json格式 二. ...
- linux 基本操作--笔记
linux 基本操作: pwd 显示当前目录 ll 用于查看文件和目录,即list,其参数比较多 -l 列出数据串,包含文件的属性和权限数据等 -a 列出全部文件,包含隐藏文件 -d 仅列出目录本身, ...
- LeetCode 十月份题目汇总
开源地址:点击该链接 前言 十月份共有60道题目,全部属于 Easy 难度的,所以公众号中分享出来的并不多,只是挑了一些感觉还可以的才分享了出来,这60道题目我按照不同类别进行了分类整理,所有源码以及 ...
- Creator 2.2.0 终于等来了这款Shader组件神器!一招搞定Effect特效
先看下视频演示: ShaderHelper2支持Creator 2.2.0 视频录完后才想起,还没在微信小游戏中测试,赶紧试试,下面是在微信开发者工具中的截图. 径向模糊 探照灯 提供了一个Shade ...
- UnityWebRequest_ZT
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using U ...