Algorithm of Blue Bridge Cup Test Questions Improves Lottery

Resource limit
Time limit: 1.0s Memory limit: 256.0MB

Description of the problem
In order to enrich the Boys’ Day activities, girls from your department set up a lottery draw. The rules are as follows:
  1. There are 7 different numbers printed on each lottery ticket, and the value range of these numbers is [1, 33];
  2 , Every time before the prize is claimed, a winning number composed of seven different numbers will be announced;
  3. A total of 7 prizes are set up, including the special prize and the first prize to the sixth prize. The prize redemption rules are as follows:
  Special Prize: All 7 numbers on the lottery must appear in the winning numbers;
  First Prize: 6 numbers on the lottery must appear in the winning numbers;
  Second Prize: 5 numbers on the lottery must appear Among the winning numbers;
  ...
  Sixth prize: 1 number on the lottery is required to appear in the winning numbers;
  Note: The order in which the numbers appear is not considered, for example, if the winning numbers are 23 31 1 14 19 17 18, the lottery ticket is 12 8 9 23 1 16 7 Since two numbers (23 and 1) appeared in the winning number, the lottery won the fifth prize.
  Now that the winning numbers and the lottery numbers Li Hua bought are known, please write a program to judge his lottery winning status.

Input format
The first line contains a positive integer n, indicating the number of lottery tickets, the second line contains 7 integers, indicating the winning number, and the following n lines each contain 7 integers, describing n lottery tickets.

The output format
is numbers separated by 7 spaces. The first number indicates the number of winning sheets for the special prize, the second number indicates the number of winning sheets for the first prize, and the third number indicates the number of winning sheets for the second prize... The 7 numbers represent the number of winning sheets of the sixth prize.

Sample input
3
1 2 3 4 5 6 7
11 12 13 14 15 16 17
12 13 14 15 16 17 18 8 7
10 9 31 30 29

Sample output
0 0 0 0 0 0 1

Data scale and agreement
30% of the data n<=100;
  70% of the data n<=1000;
  100% of the data n<=100000.

Tip: Arrays are defined as global variables, which can allocate more memory.

My idea: create two arrays num and prize, num is used to store the 7 winning numbers, and prize is used to store the number of 7 awards, each time input all the numbers of num in a loop to see if they are equal, the records are the same number of times. How many prizes can be judged by the number of passes.

#include<iostream>
#include<vector>
using namespace std;
int main()
{
	vector<int>prize(7),num(7);
	int x;
	cin >> x;
	for (int j = 0; j < 7; j++)
	{
		cin >> num[j];
	}
	int t,cnt=0;
	for (int i = 0; i < x; i++)
	{
		cnt = 0;
		for (int j = 0; j < 7; j++)
		{
			cin >> t;
			for (int k = 0; k < num.size(); k++)
			{
				if (t == num[k])
				{
					cnt++;
					break;
				}
			}
		}
		if (cnt > 0)
		{
			prize[cnt - 1]++;
		}
	}
	for (int i = prize.size()-1; i >=0; i--)
	{
		if (i != prize.size() - 1)
			cout << ' ';
		cout << prize[i];
	}
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_49418695/article/details/123764501