目录
1.斐波那契数列
避免数字过大提前对每个数进行取模
2.回文数升级版 40.00
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int a[1005];
bool judge(int x) {
int i = 0;
while (x){
a[i] = x % 10;
x /= 10; i++;
}
//检查是否为回文数
for (int j = 0; j < i / 2; j++) {
if (a[j] != a[i - j - 1])
return false;
}
return true;
}
int rev(int x) {
int ret = 0;
while (x) {
//反转数字通过不断的乘10和取余
ret = ret * 10 + x % 10;
x /= 10;
}
return ret;
}
int nums[1005];
int main() {
int n;
int m = 0;
cin >> n;
nums[m++] += n;
//构造函数简化代码
while (!judge(n)) {
n += rev(n);
nums[m++] += n;
}
cout << m -1<<endl ;
for (int i = 0; i < m; i++) {
//注意行末格式
if (i != m - 1)
cout << nums[i] << "--->";
else
cout << nums[i] << endl;
}
return 0;
}