兰聪


私信TA

用户名:dotcpp0606174

访问量:914

签 名:

等  级
排  名 2827
经  验 2060
参赛次数 0
文章发表 13
年  龄 0
在职情况 学生
学  校 鄂州职业大学
专  业

  自我简介:

TA的其他文章

参考代码:

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		Set<Integer> set = new HashSet<>();
		
		for (int i = 0; i < 7; i++) { // 将七个中奖数字添加到set
			set.add(sc.nextInt());
		}
		
		int[] arr = new int[7]; // 这个是中奖结果
		
		for (int i = 0; i < n; i++) {
			int cnt = 0;
			
			for (int j = 0; j < 7; j++) {
				if(set.contains(sc.nextInt())) { // 如果set集合里有当前输入的数字
					cnt++;
				}	
			}
			
			if(cnt != 0) { // 需要判断一下,如果cnt等于0的话arr[cnt-1]++ 就会越界
				arr[cnt-1]++;
			}
		}
		
		for (int i = arr.length-1; i >= 0; i--) {
			System.out.print(arr[i] + " ");
		}
	}

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区