东华大学 2022 oj c++ 无超纲写法 回文数

 

 

//解释都在注释里,个人认为写的还算清晰

AC代码:

#include<iostream>
#include<iomanip>
#include<math.h>
#include<cstring>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
int reverse(int num)//数字逆序函数
{
	int rev = 0;
	while (num)
	{
		rev = 10 * rev + num % 10;
		num /= 10;
	}
	return(rev);
}
int ispalin(int j)//判断是否是回文的函数
{
	if (reverse(j) == j)
	{
		return(1);
	}
	return (0);
}
int main()
{
	int a;
	cin >> a;
	while (a!=0)
	{
		cout << a << "+" << reverse(a) <<"="<< a + reverse(a);
		a = a + reverse(a);
		cout << endl;//由于输入的第一个是否是回文都要进行一次操作,就单独提出来了,话说是不是能用do while来着...
		while (ispalin(a) == 0)//根据题目要求的格式进行回文操作
		{
			cout << a << "+" << reverse(a) <<"="<< a + reverse(a);
			a = a + reverse(a);
			cout << endl;
		}
		cin >> a;
	}
	//system("pause");
	return 0;
}

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值