ACM Digital Roots
来源:互联网 发布:win7系统盘清理软件 编辑:程序博客网 时间:2024/06/06 09:46
答案错了,这是为啥嘛,我调试到没有错误啊,到底哪里错了
Problem Description
The digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is continued as long as necessary to obtain a single digit.
For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.
For example, consider the positive integer 24. Adding the 2 and the 4 yields a value of 6. Since 6 is a single digit, 6 is the digital root of 24. Now consider the positive integer 39. Adding the 3 and the 9 yields 12. Since 12 is not a single digit, the process must be repeated. Adding the 1 and the 2 yeilds 3, a single digit and also the digital root of 39.
Input
The input file will contain a list of positive integers, one per line. The end of the input will be indicated by an integer value of zero.
Output
For each integer in the input, output its digital root on a separate line of the output.
Sample Input
24390
Sample Output
63
Source
#include <iostream>#include <stdio.h>using namespace std;int fun(int temp){ int value = temp; int c,a=0; while (value>0) { a += value%10; value/=10; } if (a>=10) fun(a); else return a;}int main(){ long int value; while (scanf("%d", &value)==1) { if(value == 0) break; if (value>=10) { printf("%d\n", fun(value)); } else printf("%d\n", value); } return 0;}
0 0
- ACM Digital Roots
- (ACM)Digital Roots
- 北大ACM poj1519 Digital Roots
- 杭电ACM 1013 Digital Roots
- 杭电acm 1013 Digital Roots
- 杭电ACM-1013-Digital Roots
- 杭电ACM 1013 Digital Roots
- HDU's ACM 1013 Digital Roots
- 杭电 acm 1013 Digital Roots
- ACM 数论 hdu 1013 Digital Roots
- 杭电acm—1013 Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- Digital Roots
- 理解为什么要使用Ioc
- linux命令
- java编程——吸血鬼数字(四位)
- 黑马程序员_模版方法设计模式
- 初级算法整理,字符串的前后换位
- ACM Digital Roots
- 架构设计师与SOA
- 小小的TODO,大大的世界!
- Linux 网络相关命令
- UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position 1: ordinal not in range(128)
- hdu 1003
- Foundation框架内容
- 统计学知识
- Theano3.4-练习之多层感知机