#include #include #include #include using namespace std; string inventory(string n) { map counts; for (size_t i=0; i::iterator i = counts.begin(); i != counts.end(); ++i) { if (i->second > 0) out << i->second << i->first; } return out.str(); } void doit(string n) { string x = n; // cout << n << endl; for (int i=0; i<15; ++i) { string inv = inventory(x); // cout << " " << inv << endl; if (inv == x) { if (i == 0) cout << n << " is self-inventorying" << endl; else cout << n << " becomes self-inventorying " << "after " << i << " steps" << endl; return; } if (inv == n) { cout << n << " enters an inventory loop of length " << i+1 << endl; return; } x = inv; } cout << n << " cannot be classified after 15 iterations" << endl; } int main() { string n; while (true) { cin >> n; if (n == "-1") break; doit(n); } return 0; }