Advertisement
jakaria_hossain

codeforce - Sum of Digits

May 20th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fastread()(ios_base::sync_with_stdio(false).cin.tie(NULL));
  4. #define pb push_back
  5. int cr=0;
  6. int counter(string s)
  7. {
  8. int sum=0;
  9. for(int i=0;i<s.size();i++)
  10. {
  11. sum+=s[i]-'0';
  12. }
  13. if(s.size()==1 && cr==0)cr=0;
  14. else cr++;
  15. if(sum>9)
  16. {
  17. s.clear();
  18. while(sum>0)
  19. {
  20. int x = sum%10;
  21. char c= x+'0';
  22. s.pb(c);
  23. sum/=10;
  24. }
  25.  
  26. return counter(s);
  27. }
  28. //cr++;
  29. //if(sum==0 && cr==1)cr=0;
  30. return 1;
  31. }
  32. int main()
  33. {
  34. string s;
  35. cin>>s;
  36. int x= counter(s);
  37. cout<<cr<<endl;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement