TAP2015H  Hugo s homework
[Due to SPOJ restrictions, this problem has been modified with respect to the original version used in the Argentinian Programming Tournament of 2015 in order to have multiple test cases per input file. The original version of this problem (in Spanish) can be found at http://torneoprogramacion.com.ar/wpcontent/uploads/2015/09/pruebaTAP2015.pdf ]
Hugo goes to primary school, but he is convinced that not enough homework is being given to him. Specifically, he was recently taught how to subtract two numbers, but each day he is given a single subtraction to perform at home. Hugo knows that in order to master such a complex technique he should practice much more, so he has decided to take matters into his own hands and create his own homework.
It's not easy for Hugo to invent exercises about a subject he does not fully comprehend, so he has devised the following method to perform multiple subtractions. He starts by asking his mother for a number N, and then forms the number M containing the same digits as N in increasing order from left to right, after which he finally performs the subtraction NM. For example, if his mother chooses the number N = 321 then M = 123 and the subtraction Hugo must perform is N  M = 321123 = 198.
Hugo wouldn't want to bother his mother too often, so he will repeat this procedure using the result of the subtraction NM in one step as the number N he starts with in the next step. This will end only when at some point he reaches the value N = 0, as this case is useless to practice subtractions because he would have M = 0: Hugo already knows perfectly well that if he has no candies he cannot eat any candies, and will therefore continue to not have or eat candies forever.
Now Hugo's mother would like to know, given a number N, how many subtractions Hugo can perform if she gives him that number to start his homework. In the previous example, in the second step Hugo would have N = 198 so that M = 189 and N  M = 198  189 = 9. Then in the third step N = 9, M = 9 and N  M = 0, so here the fun ends because in the fourth step he would have N = 0. Thus, starting with the number N = 321 Hugo will perform 3 subtractions.
Input
There are multiple test cases in the input file. Each test case consists of one line containing an integer N, representing the number Hugo's mother will give him to start his homework (1 ≤ N ≤ 10^{9}).
Output
For each test case, print one line containing one integer representing the number of subtractions Hugo will perform if he starts his homework with number N.
Example
Input: 321 20 960687301 Output: 3 2 91
hide comments
viratian_070:
20170707 07:36:55
please check submission for id=19749123..logic is correct but still showing tle...plz check 

aditya_rev:
20170621 23:29:21
priority queue make it more easier :D 

madhavgaba:
20160714 18:03:01
for input use while(scanf("%lld",&num)==1) 

iloveaakanksha:
20160615 09:21:48
Finally a century on ProjectEuler , CodeForces , HackerRank , HackerEarth and SPOJ


vivekrnj:
20160331 19:50:32
nothing here.....just large prob.!!!


Utkarsh Ruhela:
20151230 11:21:12
How to end the program? 

Devashish Mathur:
20151225 10:35:36
cakewalk... beware of border case 

Mihajlo:
20151128 10:55:04
ez bf :D 

Fidel Schaposnik:
20151102 20:10:03
step 1) 20  02 = 18


Harish Meena:
20151031 23:36:19
EOF still the worst way to end the code

Added by:  Fidel Schaposnik 
Date:  20151028 
Time limit:  1s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 GOSU JSMONKEY 
Resource:  Argentinian Programming Tournament 2015 