标题:这是我遍写的杭电1003题,为什么提示我是错误答案呢
取消只看楼主
竹闲云
Rank: 2
等 级:论坛游民
帖 子:39
专家分:34
注 册:2011-10-9
结帖率:62.5%
已结贴  问题点数:18 回复次数:1 
这是我遍写的杭电1003题,为什么提示我是错误答案呢
/* Note:Your choice is C IDE */
#include "stdio.h"
void main()
{
    int a[100]={0};
    int b[100]={0};
    int h,k;
    int i,sum,m,n,p=0;
    scanf("%d",&h);
    while(h--)
    {
        p++;
        scanf("%d",&m);
        for(i=0;i<m;i++)
        {
            scanf("%d",&a[i]);
        }
        for(i=0;i<m;i++)
        {
            if(a[i]>=0)
            {
                k=i;
                break;
            }
        }
        
        for(i=k;i<m;i++)
        {
            if(i==k)
            {
                b[i]=a[i];
            }
            else
            {
                b[i]=b[i-1]+a[i];
            }
        }
        for(i=k;i<m;i++)
        {
            if(b[i]>b[i-1])
            {
                sum=b[i];
                n=i+1;
            }
            else
            {
                sum=b[i-1];
                n=i;
            }
        }
        printf("case%d:\n",p);
        printf("%d  %d  %d\n\n",sum,k,n);
    }
   
}

[ 本帖最后由 竹闲云 于 2012-8-20 13:54 编辑 ]
搜索更多相关主题的帖子: include choice 
2012-08-20 13:13
竹闲云
Rank: 2
等 级:论坛游民
帖 子:39
专家分:34
注 册:2011-10-9
得分:0 
回复 2楼 beyondyf
你看看我这个程序,为什么提示说运行出错呢
#include "stdio.h"
void main()
{
    int a[100]={0};
    int b[100]={0};
    int zs,gs,ks,js,cs,sum,i,t=0;
    scanf("%d",&zs);
    while(zs--)
    {
        t++;
        scanf("%d",&gs);
        for(i=0;i<gs;i++)
        {
            scanf("%d",&a[i]);
        }
        for(i=0;i<gs;i++)
        {
            if(a[i]<0)
            {
                cs=0;
            }
            else
            {
                cs=1;
                ks=i;
                break;
            }
        }
        if(cs==0)
        {
            for(i=0;i<gs;i++)
            {
                if(i==0)
                {
                    sum=a[0];
                    ks=0;
                    js=0;
                }
                else
                {
                    if(sum<a[i])
                    {
                        sum=a[i];
                        ks=i;
                        js=i;
                    }
                }
            }
        }   
        else
        {
            for(i=ks;i<gs;i++)
            {
                if(i==ks)
                {
                    b[ks]=a[ks];
                }
                else
                {
                    b[i]=b[i-1]+a[i];
                }
            }
            for(i=ks;i<gs;i++)
            {
                if(i==ks)
                {
                    sum=b[i];
                    js=i;
                }
                else
                {
                    if(sum<b[i])
                    {
                        sum=b[i];
                        js=i;
                    }
                }
            }
        }
        printf("case%d:\n",t);
        printf("%d %d %d\n\n",sum,ks+1,js+1);
    }   
}
2012-08-20 17:21



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




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

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