在线帮忙找bug

public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int[] arr=new int[scan.nextInt()];
        scan.nextLine();
        for(int i=0;i<arr.length;i++)
            arr[i]=scan.nextInt();
        int[] solution=new int[scan.nextInt()];
        scan.nextLine();
        for(int i=0;i<solution.length;i++){
            solution[i]=scan.nextInt();
            scan.nextLine();
        }
        boolean[] res=new boolean[solution.length];
        Set<Integer> set=new HashSet();
        set.add(0);
        for(int i=0;i<arr.length;i++){
            Iterator<Integer> iterator=set.iterator();
            Set<Integer> tmp=new HashSet();
            while(iterator.hasNext())
                tmp.add(iterator.next()+arr[i]);
            set.addAll(tmp);
        }
        for(int i=0;i<solution.length;i++){
            if(solution[i]>10000){
                System.out.println("NO");
                continue;
            }
            Iterator<Integer> iterator=set.iterator();
            boolean flag=false;
            while(iterator.hasNext()){
                int val=iterator.next();
                if(set.contains(val-solution[i])){
                    flag=true;
                    break;
                }
            }
            System.out.println(flag?"YES":"NO");
        }
    }

全部评论
认真审题,多组输入
点赞 回复 分享
发布于 2021-01-06 22:24

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务