This is an easy problem from uva judge https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2734
Brute force.
How I did it
- I read the input until I get END.
- Init a counter with 1.
- The next number is the number of digits of the input.
- If both numbers are equal I return the counter.
- Otherwise call my method again increasing the counter, and sending the new number(number of digits of the parameter number).
- I print the answer.
- Accepted!!
Hints
- The description is horrible.
- The problem is asking to generate a new number that is the number of digits of the previous one and stop when the length and the new number are equal.
Code
/* *Author: Fabian Calsina *Date: 3/5/2018 */ #include <bits/stdc++.h> using namespace std; int getMinimum(int i, string number){ stringstream ss; int digits = number.size(); ss<< digits; if(ss.str() == number) return i; return getMinimum(++i, ss.str()); } int main(){ string input; int answer; while(cin>>input){ if(input == "END") break; answer = getMinimum(1, input); printf("%d\n", answer); } return 0; }