解题报告:hdu1013 Digital Roots

时间:2023-03-09 04:26:40
解题报告:hdu1013 Digital Roots

2017-09-07 22:02:01

writer:pprp

简单的水题,但是需要对最初的部分进行处理,防止溢出

/*
@theme: hdu 1013 Digital roots
@writer:pprp
@begin:21:52
@end:21:59
@error:虽然是水题,但是还是需要对最初的处理,如果过大超过了int范围,就出错了
@date:2017/9/7
*/ #include <bits/stdc++.h> using namespace std; int main()
{
string str;
while(cin >> str && str != "")
{
long long n = ;
for(int i = ; i < str.length(); i++)
n += str[i] - '';
int ans = ;
while(n)
{
ans += n%;
n /= ;
if(n == && ans >= )
{
n = ans;
ans = ;
}
}
cout << ans << endl;
}
return ;
}