Created
January 19, 2017 12:25
-
-
Save KhaledElshamy/566c20d801c604e8c8f6e64f7e3a4acb to your computer and use it in GitHub Desktop.
B. Sum of Digits-codeforces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // working.cpp by Bill Weinman <http://bw.org/> | |
| #include <bits/stdc++.h> | |
| using namespace std; | |
| int main() { | |
| char digits[100001]; | |
| cin>>digits; | |
| int times=0; | |
| if (digits[1] != 0) | |
| { | |
| int digitsum=0; | |
| char* p = digits; | |
| while (*p != 0) | |
| { | |
| digitsum += (*p - 48); | |
| ++p; | |
| } | |
| ++times; | |
| while (digitsum > 9) | |
| { | |
| int m=digitsum; | |
| digitsum = 0; | |
| while (m != 0) | |
| { | |
| digitsum += m % 10; | |
| m /= 10; | |
| } | |
| ++times; | |
| } | |
| } | |
| cout<<times<<endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment