题解 | #查找# java易理解版本

查找

https://www.nowcoder.com/practice/d93db01c2ee44e8a9237d63842aca8aa

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
           int n=in.nextInt();
           int[] nums=new int[n];
           for(int i=0;i<n;i++){
                nums[i]=in.nextInt();
           }
           int m=in.nextInt();
           int[] targets=new int[m];
           for(int j=0;j<m;j++){
                targets[j]=in.nextInt();
           }
           for(int target:targets){
                boolean found=false;
                for(int num:nums){
                    if(num==target){ 
                        found=true;
                        break;
                    }
                }
                if(found) System.out.println("YES");
                else System.out.println("NO");
           }
        }
    }
}

全部评论

相关推荐

06-25 09:33
厦门大学 Java
程序员饺子:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司7个岗位
点赞 评论 收藏
分享
06-26 17:24
已编辑
宁波大学 golang
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-09 13:05
TMD找工作本来就烦,这东西什么素质啊😡
Beeee0927:hr是超雄了,不过也是有道理的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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