Luogu: [AHOI2001] Lottery Draw

topic description

In order to enrich the lives of the people and support certain social welfare undertakings, Beita City has set up a lottery. The rules of this lottery are:

  1. There are 7 different numbers printed on each lottery ticket, and the values ​​of these numbers range from 1 to 33.
  2. A winning number consisting of seven different numbers will be announced each time before the prize is claimed.
  3. A total of 7 awards are set up, including the grand prize and the first to sixth prizes.

The redemption rules are as follows:

  • Grand Prize: Requires all 7 numbers on the ticket to be among the winning numbers.
  • 1st Prize: Requires 6 numbers on the ticket to appear among the winning numbers.
  • Second Prize: Requires 5 numbers on the ticket to appear among the winning numbers.
  • 3rd Prize: Requires 4 numbers on the ticket to appear among the winning numbers.
  • 4th Prize: Requires 3 numbers on the ticket to appear among the winning numbers.
  • 5th Prize: Requires 2 numbers on the ticket to appear among the winning numbers.
  • Sixth Prize: Requires 1 number on the ticket to appear among the winning numbers.

Note: The numbers on the lottery ticket and the position of each number in the winning number are not considered when claiming the prize. For example, if the winning numbers are 23 31 1 14 19 17 18, the lottery 12 8 9 23 1 16 7 has two numbers (23 and 1) in the winning number, so the lottery wins the fifth prize.

Now that the winning numbers and the numbers of several lottery tickets bought by Xiao Ming are known, please write a program to help Xiao Ming judge the winning status of the lottery tickets he bought.

input format

The first line of input has only one natural number nn, which indicates the number of lottery tickets Xiaoming bought;

The second row stores 7 natural numbers between 1 and 33, representing the winning numbers;

In each of the next n lines, there are 7 natural numbers between 1 and 33, representing the n lottery tickets bought by Xiao Ming respectively.

output format

Output the winning status (the number of winning tickets) of the lottery tickets bought by Xiaoming in sequence, first output the winning tickets for the special prize, and then output the winning tickets for the first to sixth prizes in sequence.

Input and output samples

Input #1 Output #1

2                                          0 0 0 0 0 1 1
23 31 1 14 19 17 18
12 8 9 23 1 16 7
11 7 10 21 2 9 31
import java.util.Scanner;

public class Main3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt(); //n表示小明买的彩票张数
    	int []a = new int[7]; //中奖号码
    	int [][]b = new int[n][7]; //表示小明所买的 n 张彩票
    	int []sum = new int[8]; //中奖彩票张数
    	for(int i = 0; i < 7; i++) {
    		a[i] = sc.nextInt();  
    	}
    	for (int i = 0; i < n; i++) {
			for (int j = 0; j < 7; j++) {
				b[i][j] = sc.nextInt();
			}
		}
    	for (int i = 0; i < 8; i++) {
			sum[i] = 0;
		}
    	int zj = 0;  //zj代表中奖彩票与其他一张彩票上的相同数字有几个
    	for (int i = 0; i < n; i++) {
			zj = 0; 
			//一张彩票有七个数,循环七次
			for (int j = 0; j < 7; j++) {
				//一张彩票上共有七个数,将第1张彩票号码的第1个数与中奖彩票上的七个数分别比对
				for (int k = 0; k < 7; k++) {
					if (b[i][j] == a[k]) {
						zj++; 
					}
				}
			}
			//如果某张彩票有一个数字与中奖彩票相同,则zj=1,sum[1]=1,此张彩票中的是七等奖
			//如果某张彩票有两个数字与中奖彩票相同,则zj=2,sum[2]=1,此张彩票中的是六等奖
			//以此类推
			//如果有两张彩票 分别有两个数字与中奖彩票相同,zj=2,sum[2]=2
			sum[zj]++;
		}
    	//根据题目:一等奖:要求彩票上有 6 个号码出现在中奖号码中... sum[2]代表的是五等奖
    	for (int i = 7; i > 0; i--) { //i的含义与zj相同
			if (i != 1) {
				System.out.print(sum[i] + " ");
			} else {
				System.out.print(sum[i]);
			}
		}
    	sc.close();
    }
}

Original article: Luogu - Lottery Draw

Guess you like

Origin blog.csdn.net/woai_mihoutao/article/details/124599105