Skip to content

Instantly share code, notes, and snippets.

@KhaledElshamy
Created January 19, 2017 12:25
Show Gist options
  • Select an option

  • Save KhaledElshamy/566c20d801c604e8c8f6e64f7e3a4acb to your computer and use it in GitHub Desktop.

Select an option

Save KhaledElshamy/566c20d801c604e8c8f6e64f7e3a4acb to your computer and use it in GitHub Desktop.
B. Sum of Digits-codeforces
// 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