$29
1. Problem Description:
Given a string and a substring literal value with a direction value (0 or 1 means that the matching is from left to right or from right to left respectively), when the substring literal is matched from left to right with this string, the required output includes the substring content, matching direction and the number matched in the string. If required matching is from right to left, the substring must be reversed at first, and then matched with this string. Finally, the corresponding result is outputted.
For example,
Input:
string: "abcdcbabcd"
substring: "abc"
direction: 0
Output:
string: "abcdcbabcd"
substring: "abc"
direction: from left to right
number matched: 2
Input:
substring: "abcd"
direction: 1
Output:
string: "abcdcbabcd"
substring: "abcd"
direction: from right to left
reversed substring: "dcba"
number matched: 1
2. Given an integer > 1, output it with the reverse order. Restriction: DO NOT convert into type str
Example:
Input: 12345
Output: 54321
3. Given any integer > 1, if is odd, let = 3 + 1, if is even, let = /2. Repeat this until = 1.
Output at every step, separated by one space bar. Example:
Input: 6
Output: 6 3 10 5 16 8 4 2 1
4. Given positive integers , , define the array { } as follow:
1 = + ,
{ 2 = + , ≥1. 2 +1 = +
Let = 1 + 2 + ⋯ + ( ≥ 1).
Output the first which is a perfect square number (完全平方数) and larger than 10000.
Example:
Input: 3 4
Output: 12544
Explanation:
1 = 7, 2 = 10, 3 = 11, 4 = 13, 5 = 14,…, 411 = 36, 411 = 12544
**Test Method**
We use black-box test for this problem. That is to say, we prepare three sets of input for each program. Then we check whether the corresponding output result is correct.
**Submission**
The same as the previous labs.