| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 438 人关注过本帖
标题:杭电1013,为什么总是wrong answer啊,我找不出错误,请牛人帮帮忙啊
只看楼主 加入收藏
江风
Rank: 1
等 级:新手上路
帖 子:10
专家分:7
注 册:2010-9-10
结帖率:100%
收藏
已结贴  问题点数:15 回复次数:2 
杭电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
wangcheng911
Rank: 2
等 级:论坛游民
帖 子:59
专家分:45
注 册:2009-9-23
收藏
得分:10 
什么题目?
2010-09-13 23:20
江风
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
快速回复:杭电1013,为什么总是wrong answer啊,我找不出错误,请牛人帮帮忙啊
数据加载中...
 
   



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

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