解题思路:
注意事项:
参考代码:
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
int s,a=0;
cin>>s;
int m[4],flag=s;
while (flag != 6174)
{
m[0] = flag / 1000;
m[1] = (flag %1000)/100;
m[2] = (flag % 100) / 10;
m[3] = flag % 10;
sort(m, m + 4); int x = m[0] * 1000 + m[1] * 100 + m[2] * 10 + m[3];
sort(m, m + 4, greater<int>()); int y = m[0] * 1000 + m[1] * 100 + m[2] * 10 + m[3];
flag = y - x;
a++;
}
cout << a++;
return 0;
}
0.0分
3 人评分