1024. Palindromic Number (25)

本文介绍了一种算法,用于找到一个正整数及其反转数之和的回文数,并记录达到回文数所需的步骤数。若在指定步数内未找到,则输出最后结果及步数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.

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. For example, if we start from 67, we can obtain a palindromic number in 2 steps: 67 + 76 = 143, and 143 + 341 = 484.

Given any positive integer N, you are supposed to find its paired palindromic number and the number of steps taken to find it.

Input Specification:

Each input file contains one test case. Each case consists of two positive numbers N and K, where N (<= 1010) is the initial numer and K (<= 100) is the maximum number of steps. The numbers are separated by a space.

Output Specification:

For each test case, output two numbers, one in each line. The first number is the paired palindromic number of N, and the second number is the number of steps taken to find the palindromic number. If the palindromic number is not found after K steps, just output the number obtained at the Kth step and K instead.

Sample Input 1:
67 3
Sample Output 1:
484
2
Sample Input 2:
69 3
Sample Output 2:
1353
3

题意:求一个数和自己反过来的数之和,求和之后如果是回文数,输出结果和循环次数。如果到k次都不是回文数,输出最后的结果和k


第一次用的long long,没过。10^10进行100次求和,超出long long 范围

还是大数

tip:有可能本身这个数就是回文数


#include<iostream>  
#include<cstring>  
#include<cstdio>  
#include<queue>  
#include<stack>  
#include<algorithm>  
#include<vector> 
#include<set>
using namespace std;
int add(int num[],int len){
	int num2[100]={0};
	for(int i=0;i<len;i++) num2[i]=num[len-i-1];
	/*for(int i=0;i<len;i++){
		cout<<num[i];
	}
	cout<<endl;
	for(int i=0;i<len;i++){
		cout<<num2[i];
	}
	cout<<endl;*/
	int r=0;
	for(int i=0;i<len;i++){
		int fz=num[i]+num2[i]+r;
		num[i]=fz%10;
		r=fz/10;
	}
	num[len]=r;
	if(r==0) return len;
	return len+1;
}
int pd(int num[],int len){
	for(int i=0;i<len;i++){
		if(num[i]!=num[len-i-1]) return 0;
	}
	return 1;
}
int main(){
	char n[100];
	int k;
	cin>>n>>k;
	int num[100]={0};
	for(int i=0;i<strlen(n);i++) num[i]=n[strlen(n)-i-1]-'0';
	if(pd(num,strlen(n))){
		cout<<n<<endl<<0<<endl;
		return 0;
	}
	int len=strlen(n);
	for(int i=1;i<=k;i++){
		len=add(num,len);
		if(pd(num,len)){
			for(int i=0;i<len;i++) cout<<num[i];
			cout<<endl<<i<<endl;
			return 0;
		}
	}
	for(int i=len-1;i>=0;i--) cout<<num[i];
		cout<<endl<<k<<endl;
	return 0;
}




内容概要:本文深入探讨了金属氢化物(MH)储氢系统在燃料电池汽车中的应用,通过建立吸收/释放氢气的动态模型和热交换模型,结合实验测试分析了不同反应条件下的性能表现。研究表明,低温环境有利于氢气吸收,高温则促进氢气释放;提高氢气流速和降低储氢材料体积分数能提升系统效率。论文还详细介绍了换热系统结构、动态性能数学模型、吸放氢特性仿真分析、热交换系统优化设计、系统控制策略优化以及工程验证与误差分析。此外,通过三维动态建模、换热结构对比分析、系统级性能优化等手段,进一步验证了金属氢化物储氢系统的关键性能特征,并提出了具体的优化设计方案。 适用人群:从事氢能技术研发的科研人员、工程师及相关领域的研究生。 使用场景及目标:①为储氢罐热管理设计提供理论依据;②推动车载储氢技术的发展;③为金属氢化物储氢系统的工程应用提供量化依据;④优化储氢系统的操作参数和结构设计。 其他说明:该研究不仅通过建模仿真全面验证了论文实验结论,还提出了具体的操作参数优化建议,如吸氢阶段维持25-30°C,氢气流速0.012g/s;放氢阶段快速升温至70-75°C,水速18-20g/min。同时,文章还强调了安全考虑,如最高工作压力限制在5bar以下,温度传感器冗余设计等。未来的研究方向包括多尺度建模、新型换热结构和智能控制等方面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值