-->
当前位置:首页 > 题库

PROGRAMMING:The k-th step of sorting by choice

Luz5年前 (2021-05-10)题库470
This problem requires the use of selection sorting, the given $$n $$integers from small to large to sort, output the $$k $$row ($$k $$from $$0 $) after sorting results.
The algorithm steps are as follows:
Step $$0: find the minimum number in the unordered number of $$n $$($$a [0] $~ $$a [n-1] $), and exchange it with $$a [0] $;
Step $$1: find the minimum number in the remaining unordered number of $$n-1 $$($$a [1] $~ $$a [n-1] $), and exchange it with $$a [1] $;
……
Step $$k $: find the minimum number in the remaining unordered number of $$n-k $$($$a [k] ~ a [n-1] $), and exchange it with $$a [k] $;
……
Step $$n-2 $: find the minimum number in the remaining unordered number of $$2 $($$a [n-2] $~ $$a [n-1] $), and exchange it with $$a [n-2] $.
###Input format:
The first line of input gives a positive integer of no more than 10 $$n $$and a positive integer of no more than $$n $- $$1 $$$$$. The second line gives $$n $$integers separated by spaces.
###Output format:
Output the intermediate result of the $$k $$step ($$k $$starts from $$0 $) in the sorting process in one row, that is, the value of $$a [0] $~ $$a [n-1] $$after the $$k $$step. There is a space between adjacent numbers, and there must be no extra space at the end of the line.
###Input example:
```in
4 1
5 1 7 2
```
###Output example:
```out
1 2 7 5
```







answer:If there is no answer, please comment