Analysis of C/C++ (Level 2) real questions in December 2020#中国电子学院#National Youth Software Programming Level Examination

Insert image description here

C/C++ Programming (Levels 1~8) All real questions・Click here

Question 1: Replay the specified part of the array in reverse order

Restore the first k items in an array in reverse order. For example, replay the first 3 items of the array 8,6,5,4,1 in reverse order to get 5,6,8,4,1.
Time limit: 1000
Memory limit: 65536
Input
The input is two lines: The first line contains two integers, separated by spaces, which are the number of array elements n (1 < n < 100) and the specified k (1 <= k < =n). The second line is n integers, separated by spaces between each two integers.
Output
The output is one line: output the integers in the array in reverse order according to the requirements of the topic, and separate each two integers with spaces.
Sample input
5 3
8 6 5 4 1
Sample output
5 6 8 4 1

To solve this problem, we can use the reverse order operation of the array to realize the reverse order replay of the specified part. Here is sample code to solve the problem:

#

Guess you like

Origin blog.csdn.net/gozhuyinglong/article/details/132700719