BUAA-SUMMER-PYTHON 第一次课下作业
前言
该网页含有课上和课下题目,没有题解。如要看题解(笨笨我写的,不是很好),可以移步https://github.com/Afeii1/BUAA_Summer_Python
2025年第一次课下作业
1
【Description】
Gives two integers a and b as input, returns the value of a+b+a*b.
【Input】
A line contains two integers, separated by space, representing a and b.
【Output】
An integer, the value of a+b+a*b.
【Examples Input】
1 1
【Examples output】
3
【Example description】
1+1+1*1=3
【Notes】
For 100% of test cases, a,b in [1, 10000].
2
【Description】
Given two strings s and t, returns the number of times that t appears in s. Note that each character cannot be calculated twice.
【Input】
Two lines, string s and t.
【Output】
If s contains t, outputs the number of times that t appears in s. Otherwise outputs False.
【Example Input1】
abababa |
【Example Output1】
2
【Example Input2】
ab |
【Example Output2】
False
【Notes】
The question is to count how many T does s have, not how many T appear in S
3
【Description】
Xiaoyu is swimming happily, but she is soon sad to find that her strength is not enough, swimming is very tired. It is known that Xiaoyu can swim 2 meters in the first step, but as she gets more and more tired, her strength becomes smaller and smaller, and her next step can only swim 98% of the distance of the previous step. Now Xiaoyu wants to know how many steps she needs to swim to a distance of X meters. Please program to solve this problem.
【Input】
target distance to swim.
【Output】
how many steps Xiaoyu needs to swim
【Example Input】
4.3
【Example Output】
3
【Notes】
target distance <=100-1e^-8, and may not be an integer
Chinese Citizen ID
【Problem Statement】
Chinese Citizen ID has 18 digits. The first 6 digits show where the citizen lives. The next 8 digits show the citizen’s birthday (YYYYMMDD), and followed by 3 digits of serial number. The last digit is a checksum (0,1,2,3,4,5,6,7,8,9, or letter X).
To calculate the checksum $\sum_{i=1}^{17} (a_i*b_i)$ , you need to calculate , where $a_i$ is the i-th digit of the Citizen ID, and $b_i$ is given in the table below.
| i | $b_i$ |
|---|---|
| 1 | 7 |
| 2 | 9 |
| 3 | 10 |
| 4 | 5 |
| 5 | 8 |
| 6 | 4 |
| 7 | 2 |
| 8 | 1 |
| 9 | 6 |
| 10 | 3 |
| 11 | 7 |
| 12 | 9 |
| 13 | 10 |
| 14 | 5 |
| 15 | 8 |
| 16 | 4 |
| 17 | 2 |
Then, caculate s%11 (s mod 11), and the checksum is shown in the table below:
| s%11 | checksum (last digit of Citizen ID) |
|---|---|
| 0 | 1 |
| 1 | 0 |
| 2 | X |
| 3 | 9 |
| 4 | 8 |
| 5 | 7 |
| 6 | 6 |
| 7 | 5 |
| 8 | 4 |
| 9 | 3 |
| 10 | 2 |
Li Hua has got all his classmates’ Chinese citizen ID from his teacher, but he doesn’t know the rules above, and he needs to check how many of his classmates is over 18 years old, and how many student has made a typo inputting their ID. Please solve his problem by writing a program in Python.
You only need to check if the checksum is correct according to the rules, and how many people is over 18 years old.
Note: if the student has an invalid checksum and is over 18 years old, the student should also be counted.
【Input Format】
The first line, 1 integer n, shows how many classmates he has got.
The second line, 3 integers y m d separated by space, gives a date (year, month, day).
Then followed by n lines, each line has a 18-Digits ID, shows Li Hua’s classmates’ ID (All digits or letter ‘X’, ‘X’ will alwasy be capitalized).
【Output Format】
One line, two integers x y separated by space, where x is the number of classmates that is over 18 years old at the given date, and y is the number of classmates has a incorrect checksum in their IDs.
【Sample Input】
3
2018 1 1
11010120000101001X
114514191908100028
111111201712310034
【Sample Output】
2 1
【Sample Explanation】
11010120000101001X has a faulty checksum, the last digit should be 0. This student is over 18 years old.
114514191908100028 has a correct checksum and is over 18 years old.
111111201712310034 has a correct checksum and is under 18 years old.
【Data】
1<=n<=30000.
All dates is no later than 9999-12-31 and is valid.
All ID has an valid birth date. However, its checksum may or may not be correct.
4
【Background】
Nyima’s work and rest are very irregular. He often sleeps until 3 p.m., so it takes him a long time to send messages back and forth. There are too many messages in various group chats. He just wants to reply to his content. Please help him filter the messages.
【Description】
Given n lines of messages as input, it is required to filter out the messages containing @ all and @ nyima from the messages, first output all the messages of @ all (the messages are sorted in ascending order according to dictionary order), and then output all the messages of @ nyima (the messages are sorted in descending order according to dictionary order)
【Input】
Several lines, each line represents a message (the whole line is the content of the message, including the part before the colon)
Ensure that the last line, no new messages, represents the end of input, and the last line is not included in the message
【Output】
Each line outputs a message, indicating the filtered information. Pay attention to sorting according to the requirements in the title description
【Example Input】
xuemei: zhujiao gege, I don't know how to use python @nyima |
【Example Output】
hwjj: @all dajiji de ti zen me hai mei chu hao |
【Notes】
- Data limit: 1 < = the number of filtered messages < = the total number of messages < = 50. If this condition is met, the number of @ all messages or @ nyima messages may be 0 (at this time, no extra empty lines can be output)
- There is no message containing both @ all and @ nyima



