数组存放每一次运算后的结果,若有重复则满足小明心意。
#include <iostream>
using namespace::std;
using std::cout;
using std::cin;
int pfh(int n)
{
int sum = 0;
while(n != 0)
{
int t=n%10;
sum = sum+t*t;
n = n/10;
}
return sum;
}
int wlxm(int n)
{
int js=0;
int nums[1000];
while(n != 1)
{
nums[0]=n;
n=pfh(n);
for(int i=0; i<=js; i++)
{
if(nums[i] == n)
{
return 0;
}
}
js++;
nums[js]=n;
}
return 1;
}
int main()
{
int n;
cin >> n;
int flat=wlxm(n);
if(flat == 1)
{
std::cout << "yes";
}
else
{
std::cout << "no";
}
return 0;
}