BUAA-SUMMER-PYTHON 第三次课下作业
前言
该网页含有课上和课下题目,没有题解。如要看题解(笨笨我写的,不是很好),可以移步https://github.com/Afeii1/BUAA_Summer_Python
第一题
【Problem Description】
Write a program that can input a three-digit positive integer and output the corresponding number in reverse order. If the input number is not a three-digit positive integer, output -1.
【Input Format】
Input a three-digit positive integer.
【Output Format】
Output the value of the number after reversing the digits.
【Sample Input】
356
【Sample Output】
653
【Explanation】
The positive integer value input is 356. Swapping the ones and hundreds digit gives the result 653. If the input positive integer is 300, then the output is 3.
第二题
【Problem Description】
Implement a simple calculator: Read two integer operands (data1 and data2) and an operator (op) from the console, and calculate the expression data1 op data2. The operator op can be one of the followings: +, -, *, or /.
【Input Format】
Input the operands and operator from the console:
First, input two integers as the operands, separated by a space, representing data1 and data2.
Next, input a character as the operator op, which can be ‘+’, ‘-‘, ‘*’, or ‘/‘.
Leave a space between data1, data2, and op. Refer to the sample input for specific format.
【Output Format】
Output the result of the calculation to the console. If division is performed and the value is fully divisible, output the result as an integer. Otherwise, output the value rounded to two decimal places.
【Sample Input】
23 5 *
【Sample Output】
115
【Explanation】
In the input, the first operand is 23, the second operand is 5, and the operator is ‘*’. The calculator performs multiplication to the operands 23 and 5. The result is 115.
第三题
【Problem Description】
Write a program to find the longest common substring between two input strings, s and t.
【Input Format】
Read the strings s and t from the console, each on a separate line. Both s and t can consist of any arbitrary characters, with lengths not exceeding 50 characters. The input data should only have one unique longest common substring. If there is no common substring, print “No Answer”.
【Output Format】
Print the longest common substring of s and t on a separate line, followed by a newline character.
Algorithm hint: Use an integer counter to keep track of the current matching length and a character array to store the current matching substring. If a longer substring is found, update the counter and array accordingly.
【Sample Explanation】
Assume the following input is entered into the console:
aabcdababce
12abcabcdace
The output is:
abcda
第四题
【Problem Description】
There are two rectangles, A and B, positioned arbitrarily on a plane. Write a program to calculate the area of their intersection (shaded region in the diagram). (0 ≤ a, b ≤ 1000)
【Input Format】
Read two lines from standard input, each containing four integers separated by spaces, in the following format:
Ax1 Ay1 Ax2 Ay2
Bx1 By1 Bx2 By2
Here, (x1, y1) represents the coordinates of the top-left corner of the rectangle, and (x2, y2) represents the coordinates of the bottom-right corner. All coordinate values are integers ranging from 0 to 1000.
【Output Format】
Print an integer to standard output, which represents the area of the intersection between the two rectangles (can be 0). End the output with a newline character.
【Sample Input】
0 2 2 0
1 4 3 1
【Sample Output】
1
【Explanation】
The intersection area of the two rectangles is 1.
第五题
【Problem Description】
Write a program to convert a general infix expression, composed of single-digit integers, into a postfix expression (Reverse Polish notation). Assume that the input is a valid expression.
【Input Format】
Input a valid infix expression (without spaces) and end the input with a newline character. The expression should have a maximum of 80 characters.
【Output Format】
Output the postfix expression.
【Sample Input】
(6+2)*5-8/4
【Sample Output】
62+5*84/-
【Explanation】
The input is a valid infix expression (without spaces), and the output is the corresponding postfix expression.



