1136 A Delayed Palindrome (20 point(s))

数控弯管机xyz转换ybc的算法_花了一年时间开发的三维弯管机交互式转档软件(三维管子模型UG,SOLIDWORK,PRO/E文件转成YBC)... 在弯管机加工中,由管子模型生成可直接进行弯管加工的YBC数据可以大大提高弯管编程过程.传统的做法是先用dxf数据文件(用autocad绘制管子的轴心线数据)转出XYZ数据,然后由XYZ数据转成YBC数据,而且大部分厂家对文件版本以及软件做管方式都有不少限制,这大大花费了用户的时间跟精力.随着企业的信息化管理以及不断的技术升级,传统用autocad线条模式来描述管子的方式正在被用户用PRO/E,UG... 阅读详情

1136 A Delayed Palindrome (20 point(s))

Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ with 0≤a​i​​<10 for all i and a​k​​>0. Then N is palindromic if and only if a​i​​=a​k−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.

回文串判断、基于字符串的加法。

 注意点:

1. 在每一次迭代之前先判断是不是回文串;

2. 字符串的加法注意考虑进位,注意最终加法结果翻转。

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
bool isPal(string s){
	for(int i=0;i<s.length()/2;i++){
		if(s[i]!=s[s.length()-1-i]) return false;
	}
	return true;
}
string add(string a){
	string b = a;
	reverse(a.begin(),a.end());
	int carry=0;
	string ans="";
	for(int i=0;i<a.length();i++){
		int c = a[i]-'0'+b[i]-'0'+carry;
		carry = c/10;
		ans+=char(c%10 +'0');
	}
	if(carry!=0) ans+=char(carry+'0');
	reverse(ans.begin(),ans.end());
	cout<<b<<" + "<<a<<" = "<<ans<<endl;
	return ans;
}
int main(void){
	string s;cin>>s;
	bool flag = false;
	for(int i=0;i<10;i++){
		if(isPal(s)){//先判断是否回文 
			flag = true;
			cout<<s<<" is a palindromic number."<<endl;
			break;
		}
		s = add(s);
	}
	if(!flag) cout<<"Not found in 10 iterations."<<endl;
	return 0;
}

 

KubeVela入门到精通-K8S多集群交付 KubeVela是一个功能强大、易于使用、高度可扩展的应用交付与管理平台。它基于Kubernetes和OAM 技术构建,通过开放应用模型(OAM)来作为顶层的抽像,提供了声明式部署、多集群/混合环境支 持、插件与扩展性、中心化管控以及易于使用与可观测性等特点。 阅读详情

相关推荐

从零到一:AnythingLLM与Ollama的本地知识库搭建实战

本文详细介绍了如何使用AnythingLLM与Ollama从零开始搭建本地知识库,涵盖技术选型、环境部署、系统配置及优化策略。通过RAG技术架构,实现安全高效的文档管理与智能问答,特别适合企业及个人构建私有化知识管理系统。

weixin_29079643的博客 566

『1136」A Delayed Palindrome

Consider a positive integerNwritten in standard notation withk+1digitsai​aswithfor alland. ThenNispalindromicif and only if for all. Zero is written 0 and is also palindrom...

weixin_52435933的博客 152

PCI Express 权威指南:从协议原理到芯片实现

目录 全文总览第一部分:PCIe体系结构概览第1章 互连技术的演进与PCIe的诞生1.1 从ISA到PCI:并行总线的辉煌与瓶颈1.2 PCI-X的尝试与局限1.3 串行革命:从AGP、PCI到PCIe的范式转移1.4 PCIe的核心优势第2章 PCIe系统全局视角2.1 系统拓扑:Root Complex, Switch, Endpoint的职能与关系2.2 拓扑结构实例:服务器、工作站、嵌入式系统2.3 枚举与配置:系统如何发现和组织PCIe设备2.4 地址空间第3章 PCIe协议分层架构3.1 分层模

qq_42882296的博客 2895

PAT甲级刷题之路——A1136 A Delayed Palindrome

PAT A1136 A Delayed Palindrome(20分)原题如下题目大意错误总结AC代码结语 原题如下 A1136 A Delayed Palindrome 题目大意 字符串和自己翻转后的字符串对应的数字相加,直至达到回文串停止,若迭代超过10次也停止。 错误总结 一开始我没看到字符串长度不超过1000,则即使使用long long型也不行,故要使用大整数相加的方法。 先翻转然后相...

qq_43677396的博客 324

CocosCreator | 自定义启动页之H5

01 效果对比 默认启动页: 自定义启动页: 02 启动页存在的意义 我们在 creator 中的开发的游戏都是基于 cocos engine,所以在展示我们的游戏之前,是必须要先加载 cocos engine,然后才是我们自己的业务代码 流程图如下: 而构建完成后未精简的 cocos engine 代码为 1.9M 如果再加上物理相关代码的话,一共是2M 别忘了,我们自己的首场景也要加载过程哦 所以,从游戏启动,到真...

Valiancer 5899

手把手教你在VirtualBox里复活Win98,并搞定驱动和文件传输(含资源寻找攻略)

本文详细指导如何在VirtualBox中安装和配置Windows 98,包括驱动安装、文件传输等实用技巧。通过逐步教程和资源寻找攻略,帮助技术爱好者完美复刻这一经典操作系统,满足怀旧或兼容性测试需求。

weixin_29596051的博客 327

【PAT刷题甲级】1136.A Delayed Palindrome

1136 A Delayed Palindrome (20 分) Consider a positive integer N written in standard notation with k+1 digits ai as ak ⋯a1 a0 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 pal

C_greenbird的博客 298

保姆级教程:用HFSS 2023 R2搞定GPS右旋圆极化微带天线(从建模到优化全流程)

本文提供了一份详细的HFSS 2023 R2教程,指导读者从零开始设计GPS右旋圆极化微带天线。涵盖建模、仿真和优化全流程,特别关注圆极化特性的实现与优化,帮助工程师快速掌握天线设计的关键技术。

weixin_42557830的博客 171

PAT 甲级 1136  A Delayed Palindrome

1136 A Delayed Palindrome (20 point(s)) Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ with 0≤a​i​​&lt;10 for all i and a​k​​&gt;0. Then N is pal...

漫浸天空的雨色的备忘录~ 716

COMSOL有限元仿真深度指南:连接薄结构与实体结构(I)

COMSOL有限元仿真深度指南:如何在结构力学仿真中连接薄结构与实体结构?

忘了面孔的Batou 1万+

PostgreSQL:Patroni 高可用架构,基于etcd的自动故障转移集群

本文详细介绍了基于Patroni和etcd构建PostgreSQL高可用集群的方案。Patroni作为外部守护进程,通过etcd分布式协调服务实现自动故障转移、主节点选举等关键功能,弥补了PostgreSQL原生缺乏自动故障转移的不足。文章涵盖核心架构(3节点PG+3节点etcd)、环境规划、etcd集群部署(包括配置验证)以及Patroni安装配置的关键步骤,特别强调了Patroni自动初始化PG实例、配置同步复制等生产级特性。该方案通过外部组件协同工作,在不修改PG源码的情况下实现了生产环境所需的高可用

数据知道的博客 2494

PAT甲级1136 A Delayed Palindrome (20 分)

1136A Delayed Palindrome(20分) Consider a positive integerNwritten in standard notation withk+1digitsa​i​​asa​k​​⋯a​1​​a​0​​with0≤a​i​​<10for allianda​k​​>0. ThenNispalindromi...

Dexter 223

【图像超分】论文复现:新手入门必备!Pytorch实现SRGAN!手把手详细教程!代码注释详尽!可用于训练自己的数据集!实时验证模型性能!绘制PSNR曲线图!附训练好的各放大倍数的模型权重文件!

【图像超分】论文精读:SRResNet/SRGAN【图像超分】论文复现:万字长文!Pytorch实现SRResNet代码修改无报错!踩坑全记录!适合各种深度学习新手!帮助你少走弯路!附修改后的代码和PSNR最优的模型权重文件!请配合上述论文精读文章使用,效果更佳!与原论文描述不一样的实现部分,也即可以修改的部分数据集使用:论文中是ImageNet随机选35000张图像,本文是VOC2012数据集16700张图像。数据集预处理:裁剪大小不同,论文是96×96,本文是88×88。

主要更新底层视觉(去噪、超分等)相关的科研内容,形式为【论文精读】+【论文复现】 6855

1136 A Delayed Palindrome (20 point(s))

题解 回文串简单判断。 #include&lt;iostream&gt; #include&lt;string&gt; #include&lt;cstdio&gt; #include&lt;algorithm&gt; using namespace std; bool isPalin(string a) { string b = a; reverse(a.begin(), a.end(...

徐伯莱 409

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

【PAT】A1136 A Delayed Palindrome (20point(s))

文章目录A1136 A Delayed Palindrome (20point(s))Input Specification:Output Specification:Sample Input 1:Sample Output 1:Sample Input 2:Sample Output 2:CodeAnalysis Author: CHEN, Yue Organization: 浙江大学 Time...

Duke 233

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

1136 A Delayed Palindrome (20point(s)) - C语言 PAT 甲级

* 此题难点在于大数的相加。思路是让数组存数字时,个位数在数组低位 a[0] 上,此时两数相加可直接进位,省去进位移动数组的麻烦 1. 读取初始值时特殊处理一次即可 2. 利用自定义函数逆转数组,输出数组即可

有三只土豆 227

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

PAT_甲级_1136 A Delayed Palindrome (20point(s)) (C++)【签到题/字符串处理】

目录 1,题目描述 题目大意 2,思路 3,AC代码 4,解题过程 1,题目描述 palindrome:回文数; Sample Input 1: 97152 Sample Output 1: 97152 + 25179 = 122331 122331 + 133221 = 255552 255552 is a palindromic number. ...

&再见萤火虫&的博客 262

PAT(A) 1136 A Delayed Palindrome (20 point(s))

#include<bits/stdc++.h> using namespace std; string add(string sa, string sb){ string sc = ""; int n = sa.size(), tag = 0; for(int i = n-1; i >= 0; i--){ char c = sa[i] + sb[i] - '0' + tag; if(c > '9') c -= 10, tag

Anpotan的博客 113

1136 A Delayed Palindrome (20 point(s))字符串和整数转换,字符串和字符数组

最后一个测试点段错误,18分 反正我用指针经常段错误?或者大整数运算越界? 1⃣️sscanf,sprintf的头文件是cstring 将字符串转化成整数: sscanf(字符数组名,“整数类型,可以是%lld,%d,%lf等等”,&整数变量) 将整数转换成字符串: sprintf(字符数组名,“整数类型,可以是%lld,%d,%lf等等”,整数变量) 它们参数只差了一个 &,注意不能是string 2⃣️字符数组不能直接赋值,使用strcpy(str1,str2)可以将str2的值赋给st

qq_42835526的博客 128

1136 A Delayed Palindrome (20 分)

Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ with 0≤a​i​​&lt;10 for all i and a​k​​&gt;0. Then N is palindromic if and only if a​i​​=a​k−i​​ for...

acm_zh的博客 609

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 &lt;= ai &lt; 10 for all i and ak &gt; 0. Then N is palindromic i...

longtails的博客 543

1136 A Delayed Palindrome (20 分)

Consider a positive integer N written in standard notation with k+1 digits a​i​​ as a​k​​⋯a​1​​a​0​​ with 0≤a​i​​&lt;10 for all i and a​k​​&gt;0. Then N is palindromic if and only if a​i​​=a​k−i​​ for...

SourDumplings的博客 165

1136. A Delayed Palindrome (20)[字符串处理]

1. 原题:https://www.patest.cn/contests/pat-a-practise/1136 2. 思路: 题意:字符串处理。 给出一个数a,判断多少步可以计算出一个回文。 打印出计算过程。 比较简单,写个加法函数就好了。 已AC. 3. 源码 #include #include #include using namespace std; string a

坚不萌 279

1136 A Delayed Palindrome (20 分)

Consider a positive integerNwritten in standard notation withk+1digitsa​i​​asa​k​​⋯a​1​​a​0​​with0for allianda​k​​>0. ThenNispalindromicif and only ifa​i​​=a​k−i​​for alli. Zero...

weixin_30612769的博客 135

PAT A 1136 A Delayed Palindrome (20 分)

### 一、题目概述 略; ### 二、思路 加法过程中需要注意的问题: (1)进位问题 每次迭代计算该位相加结果,用carry保存进位值。若计算结束后carry非零,则A数组增加一位。 (2)使用向低位进位的方式运算,运算后逆置数组。 ### 三、代码 ```cpp #include <cstdio> #include <vector> #include <algorithm> using namespace std; bool ispld( vector<int> A ) { for( i

Siumai's Blog 209

1136. A Delayed Palindrome (20) 大数模拟

1136. A Delayed Palindrome (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Consider a positive integer N written

zhangchaosd的博客 1203
上一篇: 1097 Deduplication on a Linked List (25 point(s))
下一篇: 1113 Integer Set Partition (25 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值