#include <iostream>
using namespace std;
void getK(int k, int& times)
{
int a, b, c, d;
a = k%10;
b = k/10%10;
c = k/100%10;
d = k/1000%10;
if(a<b)
{
int t = a;
a = b;
b = t;
}
if(c<d)
{
int t = c;
c = d;
d = t;
}
if(a<c)
{
int t = a;
a = c;
c = t;
}
if(b<d)
{
int t = b;
b = d;
d = t;
}
if(b<c)
{
int t = b;
b = c;
c = t;
}
int num0 = a*1000+b*100+c*10+d;
int num1 = a+b*10+c*100+d*1000;
int result = num0 - num1;
if(result==k)return;
else
{
times++;
getK(result, times);
}
}
int main()
{
int T;
cin>>T;
for(int i = 0; i < T; i++)
{
int n, times=1;
cin>>n;
getK(n, times);
cout<<times<<endl;
}
return 0;
}
6174问题
最新推荐文章于 2022-04-09 12:42:09 发布