// one one

#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>  //log10
#include <algorithm> //find
#include <sstream>
#include <string>
using std::ofstream;
using std::ifstream;
using std::cout;
using std::cin;
using std::vector;
using std::find;
using std::string;
using std::istringstream;


int counter(vector<int> v, int numeral) {
	int cntr{};
	for (int i = 0; i < v.size(); ++i) {
		int x = v[i];
		while(log10(x)>=0) {
			if (x % 10 == numeral) ++cntr;
			x /= 10;
		}
	}
	cout << "you have " << cntr << " of " << numeral << std::endl;
	return cntr;
}

int main() {
	vector<int> digits(10), number, nextNumber;;
	char c{};
	//uint64_t x{};
	string s;
	cout << "Enter an int: ";
	getline(cin, s);
	istringstream is{ s };
	while (is >> c) {
		number.push_back(c - 48);
	}
	cout << "You entered ";
	for (int i : number) cout << i;
	//cin.get();
	int sz = number.size(); // int(log10(x));
	vector<vector<int>> history;  //to keep track of the sequence
	/* int pow10{ 1 };
	for (int i = 0; i < sz; ++i) pow10 * 10; */
	/*for (int i = sz; i >= 0; --i) {
		number[sz - i] = x % 10;
		x /= 10;
	}
	for (int i = sz; i > 0; --i)
		cout << number[i-1];*/
	cout << '\n';
	//cin.get();
	ofstream outFile("sequence11111111111111111111.txt");
	if (!outFile) cout << "failed to create file.";
	while (find(history.begin(), history.end(), number) == history.end()) {
		for (int i = 0; i < nextNumber.size(); ++i)
			outFile << nextNumber[i];
		history.push_back(number);
		nextNumber.clear();
		for (int i = 0; i < 10; ++i)  //count how many 0's, how many 1's, etc
			digits[i] = counter(number, i);
		for (int i = 0; i < 10; ++i) {
			if (digits[i] != 0) {
				nextNumber.push_back(digits[i]); // descriptor
				nextNumber.push_back(i); //number described
			}
		}
		
		outFile << '\n';
		number = nextNumber;
	}
	for (int i = 0; i < nextNumber.size(); ++i)
		outFile << nextNumber[i];
	outFile.close();
	ifstream ifs("sequence1111111111.txt");
	uint64_t y{};
	while (ifs >> y) cout << y << '\n';

}