Skip to content

Instantly share code, notes, and snippets.

@lp6m
Created November 15, 2014 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lp6m/793c269a23d83f8c8a79 to your computer and use it in GitHub Desktop.
Save lp6m/793c269a23d83f8c8a79 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
string IntToString(ll int number){
stringstream ss;
ss << number;
return ss.str();
}
string tmp;
string tmp2;
int main(){
int q,cnt;
cin >> q;
REP(i,q){
cin >> tmp;
tmp2 = tmp;
cnt = 0;
while(tmp.size()!=1){
int mmax = -1;
FOR(i,1,tmp.size()){
string st1,st2;
FOR(j,0,i) st1 += tmp[j];
FOR(j,i,tmp.size()) st2 += tmp[j];
mmax = max(mmax,stoi(st1)*stoi(st2));
}
cnt++;
tmp = IntToString(mmax);
if(tmp==tmp2){
cnt = -1;
break;
}
}
cout << cnt << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment