主要用的了,sort和atoi,sprintf 来做,思路还是很清楚的
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<algorithm>
bool cmp(char s1,char s2)
{
if(s1<s2)
return true;
else
return false;
}
bool cmp2(char s1,char s2)
{
if(s1>s2)
return true;
else
return false;
}
using namespace std;
int main()
{
int N;
cin>>N;
while(N--)
{
char first[5];
int temp1,temp2,start,end,N=0;
cin>>first;
while(1)
{
start=atoi(first);
sort(first,first+4,cmp);
temp1=atoi(first);
sort(first,first+4,cmp2);
temp2=atoi(first);
end=temp2-temp1;
if(start!=end)
N++;
else
{ N++;
break;
}
sprintf(first,"%d",end);
}
cout<<N<<endl;
}
}