hdoj-1013-Digital Roots(九余数定理)

题目链接 

 1 #include <iostream>
 2 using namespace std;
 3 int main() {
 4     string a;
 5     int b;
 6     while(cin >> a , a != "0")
 7     {
 8         b = 0;
 9         for(int i = 0;i < a.length();i ++)
10         {
11             b += a[i] - '0';
12         } 
13         b = b % 9;//九余数定理:所有位置上数字之和%9 == 这个数字%9 
14         if ( b == 0) b = 9;//90 输出9,否则%9输出0 
15         cout << b << endl;
16     }
17     return 0;
18 }
原文地址:https://www.cnblogs.com/slothrbk/p/8985932.html