前言

成绩出来了,大力推荐这个暑期课程,可以是全英,也可以是一般专业,最重要是给分很好!

该网页含有课上和课下题目,没有题解。如要看题解(笨笨我写的,不是很好),可以移步https://github.com/Afeii1/BUAA_Summer_Python

第一题

【Problem Description】

Sort the grades for a class of students.

Input the names and grades of the students (maximum of 50 students in a class) into the console, and then output the names and grades of the students in descending order of their grades. If two students have the same grade, they are to be sorted according to the order of input.

【Input Format】

Input the names and grades of the students into the console:

  1. The first line contains the number of students in the class.

  2. Each subsequent line contains the name and grade of a student, separated by a space. The grade must be an integer number.

【Output Format】

Output the names and grades of the students in descending order of their grades. Each line should contain the name in English characters (with 15 string padding) and grade (with 5 string padding), aligned according to the default format. If two students have the same grade, they are sorted according to the order of input.

【Sample Input】

4
aaa 50
bbb 70
ccc 65
ddd 90

【Sample Output】

############ddd###90
############bbb###70
############ccc###65
############aaa###50

(Note: The “#” sign represents a space)

【Explanation】

The names and grades of four students are input into the console, and the program outputs the grades in descending order.

第二题

2.(509664)

【Problem Description】
Write a program to count the maximum nesting level of curly braces in a given C source code and output the nested sequence of curly braces. The source code does not contain any syntax errors.
Note:

  1. Curly braces within comments (//) should be ignored and not counted.

  2. Curly braces will not appear within string literals in the source code.

【Input Format】

The C source code file to be processed is named input.c and located in the current directory.

【Output Format】

Output the maximum nesting level of curly braces on the console, followed by the sequence of curly braces in the order of their appearance on a new line.

【Sample Input】

Suppose the content of the input.c file in the current directory is:
【Sample Output】

3 {{{}{}}}

The maximum nesting level of curly braces in the source code input.c is 3, so the output is 3.

【Explanation】

Then, output the curly braces in the order of their appearance, ignoring the braces within comments, which gives the sequence: {{{}{}}}.

第三题

【Problem Description】

Input a line of string consisting of only lowercase English letters (a-z), where characters may be repeated, and the length of the string does not exceed 10000 characters.

From this string, select a certain number of characters in order (not necessarily adjacent) to form a new string, called a “sub-sequence.” If every two adjacent characters in the sub-sequence string are either equal or the later character is greater than the previous one, it is called an “ascending subsequence.” Write a program to find the length of the longest ascending sub-sequence string in the input string.

For example, for the input string “abdbch,” the ascending sub-sequences that can be formed are: “abd,” “abch,” “bbch,” “abbch,” and so on. Among them, the longest ascending sub-sequence string is “abbch,” with a length of 5.

【Input Format】

Read a line of string from console. The string should not contain any spaces and must end with a newline character.

【Output Format】

Print a positive integer to console, which is the length of the longest ascending sub-sequence string. End the line with a newline character.

【Sample Input】

abdbch
【Sample Output】

5
【Explanation】

In the input string “abdbch”, the longest ascending sub-sequence string is “abbch”, with a length of 5.

第四题

【Problem Description】

(Hint:The difficulty of this question is not high, but the text of the question is long, please answer patiently.)

On a computer screen, there are N windows. The points on the boundaries of the windows also belong to the respective windows. The windows have different levels of hierarchy, and only the content of the top-most window in the overlapping area of multiple windows is displayed. When you click on a point of the screen using a mouse, if it falls within a window, you will have selected the top-most window to which the clicked position belongs, and this particular window will be moved to the top of all other windows while maintaining the order of the remaining windows. If you click on a position that does not belong to any window, the system will ignore the click. Write a program to simulate the process of clicking on windows: first, read from the standard input to get the number of windows on the screen, each window’s stacking order and position on screen (represented by the coordinates of the lower-left and upper-right corners of the windows, with higher-level windows input first), then input the number of clicks, and starting from the subsequent lines, input two integers representing the coordinates of the clicked positions. Write a program to determine the stacking order of windows after the clicks.

Assumptions:

(1) The lower-left corner of the screen is taken as the origin of the X and Y coordinates, i.e., (0, 0). All input coordinate values are integers and are greater than or equal to 0 and less than or equal to 1000.

(2) The output for the window stacking sequence starts from the window number of the top-level window after the last click, and each number is separated by a space. The last space after the last number is optional.

(3) The number of windows is greater than 0 and less than or equal to 10, and the number of clicks is greater than 0 and less than or equal to 20.

【Input Format】

First, input the number of windows, and then starting from subsequent new lines, input five integers representing the window number, the horizontal and vertical coordinates of the bottom-left corner, and the horizontal and vertical coordinates of the top-right corner, separated by a single space. Then input the number of clicks, and then starting from subsequent new lines, input two integers representing the horizontal and vertical coordinates of each click, separated by a single space. After the last pair of coordinates is input, give a newline character.

【Output Format】

Output the stacking sequence of each window starting from the window number of the top-level window after the last click. Each window number should be separated by a space. The last space after the last number is optional.

【Sample Input】

4
1 43 31 70 56
2 50 24 80 50
3 23 13 63 42
4 57 36 90 62
5
47 28
73 40
60 38
72 52
35 56
【Sample Output】

4 2 3 1
【Explanation】

For the given input, there are 4 windows on the screen. The top-most window has the bottom-left and top-right coordinates (43, 31) and (70, 56), with a window number of 1. The subsequent windows have the bottom-left and top-right coordinates (50, 24) and (80, 50), (23, 13) and (63, 42), (57, 36) and (90, 62), with window numbers 2, 3, and 4, respectively. The first click is at coordinates (47, 28), which falls on window number 3. So, window number 3 becomes the new top-level window, and the stacking sequence becomes (3, 1, 2, 4). The second click is at (73, 40), which falls within the overlapping area of window numbers 2 and 4. As window number 2 is above window number 4, the click is registered on window number 2, which window 2 becomes the new top-level window. The stacking sequence is now (2, 3, 1, 4). The third click is at (60, 38), which is within the overlapping area of all windows. Since it falls within the top-level window number 2, the stacking sequence remains unchanged. The fourth click is at (72, 52), which falls only within window number 4. So, window number 4 becomes the new top-level window, and the stacking sequence becomes (4, 2, 3, 1). The fifth click is at (35, 56), which does not belong to any window. Therefore, the stacking sequence remains unchanged. In the end, window number 4 is the top-level window, followed by window number 2, 3, and 1.

第五题

【Background】

The eight queens problem is an old and famous one. There are eight queens on an 8*8 grid chess table. Queens can’t attack each other, that is, any two Queens can’t be in the same row, the same column or the same diagonal line. How many kinds of scenarios are there.

After learning the content of this week’s course, Xiaoming has worked out 92 solutions to the eight queens problem in Python, but he has a new question: assuming that a queen has been placed on the chessboard, how many ways can the rest queens put?

【Description】

For the extension of the eight queens problem, given the position of one queen in the chessboard, how many ways can the other seven queens put?

【Input】

One line, two integers x, y. Represents the row and column values of a given queen.

【Output】

A row, an integer, the number of pendulums of the remaining seven queens given a queen’s position.

【Example Input】

1 1
【Example Output】

4
【Example Description】

There are four pendulum methods

example1:

X O O O O O O O

O O O O X O O O

O O O O O O O X

O O O O O X O O

O O X O O O O O

O O O O O O X O

O X O O O O O O

O O O X O O O O

example2:

X O O O O O O O

O O O O O X O O

O O O O O O O X

O O X O O O O O

O O O O O O X O

O O O X O O O O

O X O O O O O O

O O O O X O O O

example3:

X O O O O O O O

O O O O O O X O

O O O X O O O O

O O O O O X O O

O O O O O O O X

O X O O O O O O

O O O O X O O O

O O X O O O O O

example4:

X O O O O O O O

O O O O O O X O

O O O O X O O O

O O O O O O O X

O X O O O O O O

O O O X O O O O

O O O O O X O O

O O X O O O O O