调了一晚上还是没找出问题来,求大神拯救小白

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int count=0;
        while(in.hasNext()){
            int n = in.nextInt();//n个人
            int t = in.nextInt();//犯罪值和上限
            int c = in.nextInt();//连续c名
            int[] a = new int[n];
            
            for(int i = 0;i<n;i++){
                a[i] = in.nextInt();
            }
	int[] sum = new int[n+1];//定义一个n+1长度的数组, 表示前n项和,sum[0]表示前0项和,就是0
        sum[0]=0;
            for(int k=1;k<=n;k++){
                sum[k]=sum[k-1]+a[k-1];  
            }
            for(int j=c;j<=n;j++){
             	if((sum[j]-sum[j-c])<=t){//减出来的结果是长度为c的子数组
                	count++;
            	}
                
            }

                    System.out.println(count);
        }

        
    }
}
题目地址:http://www.nowcoder.com/practice/b7b1ad820f0a493aa128ed6c9e0af448?tpId=49&tqId=29287&rp=1&ru=/ta/2016test&qru=/ta/2016test/question-ranking
在自己电脑上试了几组都通过了,在线提交一直百分之十通过。。。。。。求大神解救小白,看了大半天了,还是看不出来
全部评论
一楼说得对,你把count放入到while中就行了。
点赞 回复 分享
发布于 2016-09-05 09:15
 你的count每次没有重置为0
点赞 回复 分享
发布于 2016-09-05 01:57

相关推荐

11-03 13:18
门头沟学院 Java
包行:平时怎么刷算法题的哇,字节的手撕听说都很难
字节跳动工作体验
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务