| 6 | #include<bits/stdc++.h> |
| 7 | using namespace std; |
| 8 | int main() |
| 9 | { |
| 10 | ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //this line is to make the input output operation faster |
| 11 | string s; //string define |
| 12 | int n,sum=0; //variables define we need in our problem sum is counter for the steps and n is the resulting number of adding operation |
| 13 | cin>>s; //take the input number as string |
| 14 | if(s.length()==1){cout<<sum<<endl; return 0;} //check if the length is already one digit so we prit it easily |
| 15 | else{ |
| 16 | while(1){ //infinite loop until we get the wanted condition |
| 17 | int n=0; //making the resulting zero every iteration to don't be affected with the last number |
| 18 | for(int i=0;i<s.length();i++) n+=(int)(s[i]-'0'); //calculating the resulting number of adding all the didgits |
| 19 | s=to_string(n); //trasform the resulting number to string |
| 20 | sum++; //add one more step to the sum |
| 21 | if(s.length()==1){cout<<sum; break;} //break the code if the condition is happened and print the result sum |
| 22 | } |
| 23 | } |
| 24 | } |
nothing calls this directly
no outgoing calls
no test coverage detected