BUAA-SUMMER-PYTHON 第二次课下作业
前言
该网页含有课上和课下题目,没有题解。如要看题解(笨笨我写的,不是很好),可以移步https://github.com/Afeii1/BUAA_Summer_Python
title: BUAA-SUMMER-PYTHON 第二次课下作业
categories:
- BUAA-SUMMER-PYTHON
- 课下
第一题
【Problem Description】
A sequence of integers, where the first element is m and the second element is n, and each subsequent element after is the sum of the previous two elements. (-100≤n≤100, -100≤m≤100)
For example, the sequence: 1, 1, 2, 3, 5, 8, 13, 21…
Write a program that can take integer values m and n as input, solve the sequence, save the sequence in a list, calculates the sum of the first 20 elements, and outputs the total.
【Input Format】
The first line of input represents the value of m.
The second line of input represents the value of n.
【Output Format】
Output the sum of the first 20 elements of the sequence. If the input data is not an integer number, output “illegal input”.
【Input Sample】
1
1
【Output Sample】
17710
第二题
【Problem Description】
There is a method to compare whether two programs are similar: extract the control structure information in the program according to the order of appearance to form a control flow string, and then calculate the similarity between the two programs according to the control flow string of the two programs.
Write a program to extract the control flow string of a C program. Only if, else, for, while, switch, case are considered, and other control flow words should be ignored. The processed C program satisfies:
1. Can be compiled by C;
2. There may be multiple statements in one line;
3. Comments, string constants and other identifiers do not contain control flow keyword strings;
【Input Format】
The C program to be processed is saved in the current directory, and the file name is: in.c.
【Output Format】
Output control flow keyword strings to the out.txt file in the current directory in the order of appearance, without any separator between keywords.
If there is no control flow keywords, output No answer to the file.
【Input Sample 1】
Suppose the content of in.c in the current directory is:
#include <stdio.h> |
【Output Sample 1】
The out.txt file will be created in the current directory and its content should be:
>forifelse
【Input Sample 2】
If the in.c source program style in the current directory is not very good, the content is as follows:
#include <stdio.h> |
【Output Sample 2】
The out.txt file will be created in the current directory and its content should be:
>ifelseifelse
【Explanation】
The source program in sample 1 contains three control flow keywords: for, if, and else.
The source program in sample 2 contains four control flow keywords: if, else, if, else.
Output them in order to out.txt.
Hint: When reading identifiers from in.c, characters other than letters, numbers, and underscores can be used as identifier separators.
第三题
【Problem Description】
Julius Caesar encryption method. This method selects an encryption key each time it encrypts, which is a number between 1 and 25, specifying the number of shifts when encrypting letters. For example, if the key is 3, then A is converted to D, Z is converted to C, and so on. The same rule applies to lowercase letters (see the example below), while other characters remain unchanged. Encrypt a file using this method.
Hint: For uppercase letters, if the encryption key is ‘key’ (‘key’ is an integer), the conversion formula is ‘A’ + ( c - ‘A’ + key ) % 26.
【Input Format】
Enter an integer between 1 and 25 as the encryption key from standard input. Then, read the file “in.txt” in the current directory, which contains multiple lines of arbitrary characters and may include empty lines. Each text line is not longer than 80 characters.
【Output Format】
Encrypt the input file contents according to the method described above. Then, output the encrypted texts to the file “out.txt” in the current directory.
【Sample Input】
If the input key is 3 and the content of the “in.txt” file is as follows:
c language is important. |
【Sample Output】
The encrypted content of the "out.txt" file is as follows: |
【Explanation】
Encrypt the contents of the input file according to the input key and conversion formula, and output the results to the file “out.txt”.
第四题
【Problem Description】
One monkey is to be selected as the king out of n monkeys. The following method is used to decide who becomes king:
n monkeys form a circle and are assigned numbers from 1 to n in sequence. Starting from the qth monkey, they count from 1 to m, and the monkey that counts to m is eliminated. The next round starts from the monkey after the one that was eliminated, and repeats the counting from 1 to m. The process repeats until only one monkey is left. The last monkey becomes the king. Determine which monkey will be selected as the king.
【Input Format】
Enter three integers n, m, and q in the console.
【Output Format】
Output the assigned number of the monkey that was selected as king.
【Input Sample】
7 4 3
【Output Sample】
4
【Explanation】
By inputting the integers n = 7, m = 4, n = 3,we get the output integer 4 as result.
第五题
【Problem Description】
Given n numbers k1, k2, …, kn, find the number of integer palindromes (回文数) in the range from not less than 10 to not more than 10^8 (one hundred million), that is divisible by all k1,k2,…,kn .
【Input form】
The first line, an integer n.
The next n lines, each with a number representing ki.
The meanings of n and ki can be referred to Problem description.
【Output format】
A palindrome number (integer) divisible by all k1,k2,…,kn, in the range from not less than 10 to not more than 10^8 per line. If there are more than one palindrome number, output all of them from small to large. If not, output “None” (without the double quotes).
【Sample input 1】
2
998244353
123456789
【Sample output 1】
None
【Sample input 2】
2
114
514
【Sample output 2】
65100156
【Example description】
Within the range, only 65100156 is a palindrome that is divisible by 114 and 514.
【Data range】
1<=n<=5, 1<=k,n<=1000



