fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define endl "\n"
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(false);
  9. cin.tie(NULL);
  10.  
  11. string s;
  12. cin >> s;
  13. if (s.length() == 1)
  14. {
  15. cout << 0 << endl;
  16. return 0;
  17. }
  18. int cnt = 0;
  19. while (s.length() > 1)
  20. {
  21. int sum = 0;
  22. for (int i = 0; i < s.size(); i++)
  23. {
  24. sum += s[i] - '0';
  25. }
  26. s = to_string(sum);
  27. cnt++;
  28. }
  29. cout << cnt << endl;
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
0