Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int p(int in)
{
	int ret = 1;
	for (int i = 0; i < in; ++i)
		ret *= 10;
	return ret;
}

int to10(vector<int>& in)
{
	int ret = 0;
	for (int i = 0; i < in.size(); ++i)
	{
		ret *= 10;
		ret += in.at(i);
	}

	return ret;
}

vector<int> toVec(int input, int L)
{
	vector<int> in;
	for (int i = 1; i <= L; ++i){
		in.push_back((input % p(i)) / p(i - 1));
	}

	reverse(in.begin(), in.end());

	return in;
}

int getLarge(vector<int> in)
{
	int ret = 0;
	while (!in.empty()){
		ret *= 10;
		auto it = max_element(in.begin(), in.end());
		ret += *it;
		in.erase(it);
	}
	return ret;
}

int getSmall(vector<int> in)
{
	int ret=0;
	while (!in.empty()){
		ret *= 10;
		auto it = min_element(in.begin(), in.end());
		ret += *it;
		in.erase(it);
	}
	return ret;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int p(int in)
{
	int ret = 1;
	for (int i = 0; i < in; ++i)
		ret *= 10;
	return ret;
}

int to10(vector<int>& in)
{
	int ret = 0;
	for (int i = 0; i < in.size(); ++i)
	{
		ret *= 10;
		ret += in.at(i);
	}

	return ret;
}

vector<int> toVec(int input, int L)
{
	vector<int> in;
	for (int i = 1; i <= L; ++i){
		in.push_back((input % p(i)) / p(i - 1));
	}

	reverse(in.begin(), in.end());

	return in;
}

int getLarge(vector<int> in)
{
	int ret = 0;
	while (!in.empty()){
		ret *= 10;
		auto it = max_element(in.begin(), in.end());
		ret += *it;
		in.erase(it);
	}
	return ret;
}

int getSmall(vector<int> in)
{
	int ret=0;
	while (!in.empty()){
		ret *= 10;
		auto it = min_element(in.begin(), in.end());
		ret += *it;
		in.erase(it);
	}
	return ret;
}

int main()
{
	while (1)
	{
		int input, L;
		cin >> input >> L;
		if (input == 0 && L == 0)
			break;

		vector<int> in;

		vector<int> ret = {input};
		int tmp;
		auto it = ret.begin();

		while (1)
		{
			in = toVec(input, L);
			tmp = getLarge(in) - getSmall(in);
			ret.push_back(tmp);
			if ((it = find(ret.begin(), ret.end(), tmp)) != (ret.end()-1))
			{
				cout << it - ret.begin() << " " << tmp <<" "<< (ret.end() - it) - 1 << endl;
				break;
			}
			input = tmp;
		}
		
	} 

}

Compiler output:
a.cc:71:5: error: redefinition of 'int p(int)'
   71 | int p(int in)
      |     ^
a.cc:8:5: note: 'int p(int)' previously defined here
    8 | int p(int in)
      |     ^
a.cc:79:5: error: redefinition of 'int to10(std::vector<int>&)'
   79 | int to10(vector<int>& in)
      |     ^~~~
a.cc:16:5: note: 'int to10(std::vector<int>&)' previously defined here
   16 | int to10(vector<int>& in)
      |     ^~~~
a.cc:91:13: error: redefinition of 'std::vector<int> toVec(int, int)'
   91 | vector<int> toVec(int input, int L)
      |             ^~~~~
a.cc:28:13: note: 'std::vector<int> toVec(int, int)' previously defined here
   28 | vector<int> toVec(int input, int L)
      |             ^~~~~
a.cc:103:5: error: redefinition of 'int getLarge(std::vector<int>)'
  103 | int getLarge(vector<int> in)
      |     ^~~~~~~~
a.cc:40:5: note: 'int getLarge(std::vector<int>)' previously defined here
   40 | int getLarge(vector<int> in)
      |     ^~~~~~~~
a.cc:115:5: error: redefinition of 'int getSmall(std::vector<int>)'
  115 | int getSmall(vector<int> in)
      |     ^~~~~~~~
a.cc:52:5: note: 'int getSmall(std::vector<int>)' previously defined here
   52 | int getSmall(vector<int> in)
      |     ^~~~~~~~