Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
                        
                        7年前关闭。
                                                                                            
                
        
我已经编写了代码来解决http://www.codechef.com/problems/FCTRL上的一个难题

根据我的测试,该程序适用于任何数字字符串。显然,CodeChef网站报告了错误的输出。

有人可以纠正我吗?

这是我编写的代码:

#include <stdio.h>

int main(int argc, const char * argv[])
{
    int i,iterations,target,victim1,victim2,victim3;

    scanf("%d",&iterations); //take the number of acceptable iterations.

    for(i=0;i<iterations;i++)
    {
        scanf("%d", &target); //take the number as a target input the user want's to calculate on.
        victim1=target/5;
        victim2=victim1;

        while(victim1>=5)
        {
            victim1=(victim1)/5;
            victim3=victim3+victim1;
        }

        printf("%d\n",victim2+victim3);
    }

    return 0;
}

最佳答案

victim3从未被初始化...因此它可以从任何值开始。

您应该将victim3初始化为0

10-05 22:47