当前位置:编程学习 > C/C++ >>

hoj 1760 The jackpot一维

print?#include <stdio.h>  
#include <cstring>  
int f[10001]; 
int main() 

    int n,a,ans; 
    while(scanf("%d",&n)==1&&n) 
    { 
        memset(f,0,sizeof(f)); 
        ans=-1; 
        for(int i=0;i<n;i++) 
        { 
            scanf("%d",&a); 
            if(f[i]>0) f[i+1]=f[i]+a; 
            else f[i+1]=a; 
            if(f[i+1]>ans) ans=f[i+1]; 
        } 
        if(ans>0) printf("The maximum winning streak is %d.\n",ans); 
        else printf("Losing streak.\n"); 
    } 
    return 0; 

#include <stdio.h>
#include <cstring>
int f[10001];
int main()
{
    int n,a,ans;
    while(scanf("%d",&n)==1&&n)
    {
        memset(f,0,sizeof(f));
        ans=-1;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a);
            if(f[i]>0) f[i+1]=f[i]+a;
            else f[i+1]=a;
            if(f[i+1]>ans) ans=f[i+1];
        }
        if(ans>0) printf("The maximum winning streak is %d.\n",ans);
        else printf("Losing streak.\n");
    }
    return 0;
}


分享到:

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,