Programmer's written test programming questions collection (4)

1. Please use a binary tree to sort N integer numbers in ascending order. The language is not limited.
Input description:
N integer numbers
Output description:
Print out a string of ordered integer numbers
Example 1:
Input:
10 2 5 7 12 3 8
Output:
2 3 5 7 8 10 12

2. For an array of length n, please find out the majority of elements contained in it. The majority of elements here means that the element appears in the array more than [n/3] times.
Input description:
an array of length n.
Output description:
an array contained by the majority of elements.
Example 1:
Input:
[3,2,3 ]
Output:
[3]

3. Seven Stars is not based on the rules of the Chinese Mahjong competition. The Hu card is made up of seven white cards from the southeast and northwest, plus 147,258,369 unconnected cards of other suits and no trump cards.
The seven stars that do not rely on the middle means: the east, west, north, south, and center are white, that is, there must be seven cards in the card. The other cards are made according to the following:
East, West, South, North, Middle, White + 1.47 million + 258 cakes, 369,
East , West, South, North, Middle, White, + 1.47 million, +258, +369,
East, West, South, North, Middle, White, +147, + 2.58 million +369 cake
East and West in white bread +369 +258 +147 article Wan
East and West, white bread +258 +147 +369 article Wan
East and West, white bread +147 +369 +258 Wan strip
due only when the winning hand 14 cards are needed, and the above combination has 16 cards, so in addition to the white ones in the east, west, north and south, two of the other three colors can be removed at will to form a seven-star. Our task is to assume that our 14 cards already contain the seven cards that are white in the east, west, south, north, and middle, and the other cards are the ordinal cards of Wanbing, give the other seven cards, and judge whether they can be formed. Seven stars do not rely.
Input description: The
first line of input is a positive integer T (T<=1000), indicating that there are T groups of data. Each set of data contains one row, including seven cards. Each card uses "XY" to indicate that X is the number of [1…9], and Y is one of ("w", "B", "T"), each representing ten thousand Pie sticks. Note that the same "XY" may appear, but the number will not exceed 4. Ensure that the data must be legal.
Output description:
For each group of data, output YES or NO, indicating that it can or cannot be formed into seven stars.
Example 1:
Input:
4
1T 4T 7T 2B 5B 8B 9W
1T 2T 3T 4T 5T 6T 7T
1B 2W 3T 4B 5W 6T 8W
2B 8B 5B 2B 6T 7W 4W
输出:
YES
NO
YES
NO

4. Game engineer Xiao Ming fell in love with somatosensory games after purchasing VR equipment, and recently he spent his spare time in a game called Cross Slash. When you start the game with your VR eyes on, select a piece of music first, and then you will find a NN square matrix in front of your eyes, and each grid of the square matrix has a number. Then along with the music beat, you need to make a cross slash at the opposing team according to the timing (cut off one row and one column at the same time, and after selecting the row and column, you cannot chop to the grid outside the selected row and column). After the slash is finished, the matrix will shrink to a square (N-1) (N-1). In particular, if the sum of the grid numbers obtained by the cross cut is the largest among all crosses this time, you will get a Perfect. If all the N cross cuts are Perfect, you can get the achievement of Full Combo. But Xiao Ming's mental arithmetic ability is not good, and he has not yet obtained the achievement of Full Combo. Fortunately, the initial digital square matrix corresponds to the music one-to-one, so Xiao Ming can pre-calculate the position of the cross cut and memorize it. When playing, he can select the position of the cross cut according to his memory. Xiao Ming doesn't want to write code after being in the class for a day, so he asks you to write a program to calculate the cross-cut plan for him.
Input description:
Each input data contains a test point. The first line is a positive integer N, and the size of the square matrix is ​​0<N<=500. Next N rows, each row has N numbers, the j-th number in the i-th row indicates how many numbers are in the i-row and j-column of the square matrix. For each number, it is guaranteed to be a non-negative integer and the range is [0,65535] .
Output description:
output N rows, two integers n, m in each row, n, m in the ith row means that the sum of the numbers in the nth row and the mth column is the largest when the ith slash is executed. Note: If there are multiple options at this time, output the smallest n (smaller numbers are more convenient for Xiao Ming to remember). If there are multiple options, output the smallest m. Moreover, the coordinates of n, m are for the current (N+1-i) square matrix, not for the initial N*N square matrix.
Example 1:
Input:
3
1 0 0
0 10 10
0 10 10
Output:
2 2
1 2
1 1

Guess you like

Origin blog.csdn.net/qq_34124009/article/details/107978800