题目链接:
解题思路:
关键是要写出俩层 while 循环,
其中的方向便是:
要更新内层 while 循环里的执行条件
参考代码:
#include<bits/stdc++.h>
using namespace std;
int main( )
{
int data = 0;
cin >> data;
while(data >= 10)
{
int sum = 0;
while(data)
{
sum += data % 10;
data = data / 10;
}
data = sum;//关键的一步,用来更新while里面的执行条件
}
//此时data是只有一位并且非1的数字
if(data == 1)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return 0;
}