hdu1013 Digital Roots

Posted 王宜鸣

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu1013 Digital Roots相关的知识,希望对你有一定的参考价值。

思路:

九余数定理。

http://blog.csdn.net/asd7f7/article/details/53994666

实现:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 typedef long long ll;
 6 
 7 char a[1005];
 8 
 9 int main()
10 {
11     int n;
12     while (true)
13     {
14         scanf("%s", a);
15         if (a[0] == 0)
16             break;
17         int l = strlen(a);
18         int ans = 0;
19         for (int i = 0; i < l; i++)
20         {
21             ans += (a[i] - 0);
22             ans %= 9;
23         }
24         printf("%d\n", !ans ? 9 : ans);
25     }
26     return 0;
27 }

 

以上是关于hdu1013 Digital Roots的主要内容,如果未能解决你的问题,请参考以下文章

Hdu 1013 Digital Roots

hdu-1013 Digital Roots

HDU 1013 Digital Roots(两种方法,求数字根)

hdu1013 Digital Roots

HDU 1013.Digital Roots模拟或数论8月16

解题报告:hdu1013 Digital Roots