首页 > 牛客网使用Scanner类是不是会出问题
头像
刘帧
编辑于 2020-08-04 17:11
+ 关注

牛客网使用Scanner类是不是会出问题

之前的题使用同样的代码,在eclipse上跑没问题,在牛客网上就没有输出,而且是对有的用例有输出,有的没有。

import java.util.Scanner;
import java.util.ArrayList;


public class Main{
    public static void main(String[] args){
        Scanner scan  = new Scanner(System.in);
        int n = scan.nextInt();
        int[] zhuang = new int[n];
        for(int i=0;i<n;i++){
            zhuang[i] =  scan.nextInt();
        }
        ArrayList<Integer> list = new ArrayList<Integer>();
        System.out.println(GetResult(n,zhuang,list));
    }
    
    public static int GetResult(int n,int[] zhuang,ArrayList<Integer> result){
        if(n<=0){
            result.add(0);
            return 0;
        }
        else{
            int step_max =1;
            int step[] = new int[n];
            for(int i=0;i<n;i++){
                step[i] = 1;
                for(int j=i-1;j>=0;j--){
                    if(zhuang[j]< zhuang[i]){
                        if(step[j]>=step[i]){
                            step[i] = step[j]+1;
                            if(step_max < step[i]){
                                step_max = step[i];
                            }
                        }
                    }
                }
            }
            result.add(step_max);
        return step_max;
        }
    }
}



全部评论

(0) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

近期精华帖

热门推荐