标题:杭电1013,为什么总是wrong answer啊,我找不出错误,请牛人帮帮忙啊
取消只看楼主
江风
Rank: 1
等 级:新手上路
帖 子:10
专家分:7
注 册:2010-9-10
结帖率:100%
已结贴  问题点数:15 回复次数:1 
杭电1013,为什么总是wrong answer啊,我找不出错误,请牛人帮帮忙啊
#include<stdio.h>
int main()
{
    int a[100],sum[100]={0};
    int i,j;
     for(i=0; scanf("%d",&a[i]) && a[i]!=0; i++)
         continue;//将录入的数据存进a[i]
        
    for(j=0; j<i; j++)
    {        
        while(a[j] || sum[j]>=10){      
          if(a[j]==0 && sum[j]>=10) a[j]=sum[j],sum[j]=0;//若是sum[j]为两位数的话,把sum[j]赋给a[j],使循环继续
            sum[j] += (a[j] % 10);   //从a[j]的个位的数值 一直加到a[i]的最高位的数值
            a[j] = a[j]/10;          //当加到a[j]的最高位时,这个式子会使a[j]变为零
        }
    }

    for(i=0;i<j;i++)
    {
        printf("%d\n",sum[i]);//依靠循环,将计算结果输出
    }
return0;
}

/*这是我第一次做的,少考虑了一些内容,不过思路挺清晰的,这上下的思路是一样的
#include<stdio.h>
int main()
{
    int a,sum;
    while(scanf("%d",&a)==1 && a != 0){
        sum = 0;   
        while(a || sum>=10){
            if(a==0 && sum>=10) a=sum,sum=0;
            sum += (a%10);
            a = a/10;
        }
        printf("%d\n",sum);
    }
}
*/
搜索更多相关主题的帖子: answer wrong 牛人帮 
2010-09-13 23:02
江风
Rank: 1
等 级:新手上路
帖 子:10
专家分:7
注 册:2010-9-10
得分:0 
Digital Roots
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16529    Accepted Submission(s): 4684


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.

 

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
24
39
0
 

Sample Output
6
3
 

Source
Greater New York 2000

行成于思而毁于随,业精于而荒于嬉
2010-09-14 13:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-320351-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.054900 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved