1e6,1s还是可以暴力的吧-。-
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> object;
int compute();
int main()
{
int t,ans,num,k;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&num,&k);
object.clear();
ans=num;
while(num!=0)
{
object.push_back(num%10);
num/=10;
}
while(k--)
{
ans=compute();
}
printf("%d\n",ans);
}
return 0;
}
int compute()
{
int first,second,ans,temp;
sort(object.begin(),object.end());
first=object[0]*1000+object[1]*100+object[2]*10+object[3];
second=object[3]*1000+object[2]*100+object[1]*10+object[0];
object.clear();
ans=second-first;
temp=ans;
while(temp!=0)
{
object.push_back(temp%10);
temp/=10;
}
return ans;
}