[恢]hdu 1013

2011-12-16 03:38:55

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1013

题意:求数字根。(每个数码相加,若不是单位数,再加。)

mark:wa了一次,因为数字很长,可能有900多位,不是int和longlong能处理的。

代码:

# include <stdio.h>
# include <string.h>


int numroot(char str[])
{
int i, ans = 0 ;
for (i = 0 ; str[i] ; i++)
ans += str[i] -'0' ;
return (ans-1)%9 + 1 ;
}


char str[1010] ;


int main ()
{
while (gets(str) && strcmp(str, "0"))
printf ("%d\n", numroot (str)) ;

return 0 ;
}



posted @ 2012-01-06 16:41  Seraph2012  阅读(139)  评论(0编辑  收藏  举报