题目:
题解:
#include <iostream>
#include <vector>
#include<cmath>
using namespace std;
int N1, N2, f=0, A[1005], B[10], maxn;
vector<int> ans;
signed main()
{
//初始数据左右边界
cin >> N1 >> N2;
//初始化数组
for (int i = N1; i <= N2; i++)
{
A[i] = i;
}
//如果右边界为两位整数,则执行标识为1
if (N2 > 9)
{
f = 1;
}
// 执行标识符为0时停止循环
while (f)
{
f = 0;
for (int i = N1; i <= N2; i++)
{
//跳过其中的0元素
if (!A[i])
{
continue;
}
int t1 = 1, t2 = A[i];
//求元素各位立方之和
while (t2)
{
t1 *= pow(t2 % 10,3);
t2 /= 10;
}
//求元素各位之和
while (t1)
{
t2 += t1 % 10; //由t2从新存储新一轮的元素
t1 /= 10;
}
//如果还有两位数的元素,则循环执行继续
if (t2 > 9)
{
f = 1;
}
A[i] = t2; //将新一轮的元素赋值
}
}
//找出出现个数最多的元素
for (int i = N1; i <= N2; i++)
{
B[A[i]]++;
maxn = max(maxn, B[A[i]]);
}
cout << maxn << '\n';
int count = 0; //输出的个数
//寻找个位数中出现频率最高的并输出
for (int i = 0; i < 10; i++)
{
if (B[i] == maxn)
{
count++;
if (count != 1)
{
cout << ' ';
}
cout << i;
}
}
return 0;
}
标签:PAT,int,题解,元素,乙级,N1,N2,include,刷题
From: https://blog.csdn.net/2301_79580018/article/details/139756129