Problem:
Selection Sort Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A)
1 for i = 0 to A.length-1
2     mini = i
3     for j = i to A.length-1
4         if A[j] < A[mini]
5             mini = j
6     swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini. Input The first line of the input includes an integer N , the number of elements in the sequence. In the second line, N elements of the sequence are given separated by space characters. Output The output consists of 2 lines. In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. In the second line, please print the number of swap operations. Constraints 1 ≤ N ≤ 100 Sample Input 1 6
5 6 4 2 1 3 Sample Output 1 1 2 3 4 5 6
4 Sample Input 2 6
5 2 4 6 1 3 Sample Output 2 1 2 3 4 5 6
3

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]

count = 0

for i in range(N):
    minj = i
    for j in range(i,N):
        if A[j] < A[minj]:
            minj = j
    if not i == minj:
        A[i], A[minj] = A[minj], A[i]
        count += 1
        
print(" ".join(map(str, A)))
print(count)

Solution (Python):
def selection_sort(lst):
    cnt = 0
    for i in range(len(lst)-1):
        minj = i
        for j in range(i+1, len(lst)):
            if lst[j] < lst[minj]:
                minj = j
        if lst[i] > lst[minj]:
            lst[i], lst[minj] = lst[minj], lst[i]
            cnt += 1
    return cnt

n = int(input())
lst = list(map(int, input().split()))
cnt = selection_sort(lst)
print(*lst)
print(cnt)

Solution (Python):
def selectionsort(A,N):
    cnt = 0
    for i in range(N-1):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        if minj > i:
            A[i],A[minj] = A[minj],A[i]
            cnt += 1
    print(*A)
    print(cnt)

def main():
    N = int(input())
    A = list(map(int,input().split()))
    selectionsort(A,N)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
*L, = map(int, input().split())


def SelectionSort(A,N):
	cnt = 0
	for i in range(N):
		minj = i
		for j in range(i,N):
			if A[j] < A[minj]:
				minj = j
		if A[i] > A[minj]:
			A[i], A[minj] = A[minj], A[i]
			cnt += 1
	return cnt

cnt = SelectionSort(L,n)

print(*L)
print(cnt)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

perm = 0
for i in range(N):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj]:
            minj = j
    if minj != i:
        perm += 1
    temp = A[i]
    temp2 = A[minj]
    A[i] = temp2
    A[minj] = temp
print(" ".join(list(map(str, A))))
print(perm)

Solution (Python):
def selectionSort(matrix, N):
  count = 0
  for i in range(N):
    minj = i
    for j in range(i, N):
      if A[j] < A[minj]:
        minj = j
    if A[i] != A[minj]:
      A[i], A[minj] = A[minj], A[i]
      count += 1
  return count

n = int(input())
A = list(map(int, input().split()))
count = selectionSort(A, n)
print(" ".join(map(str, A)))
print(count)

Solution (Python):
def select_sort(A, N):
    cnt = 0
    for i in range(N):
        mini_ix = i
        for j in range(i, N):
            if A[mini_ix] > A[j]:
                mini_ix = j

        if mini_ix != i:  
            A[i], A[mini_ix] = A[mini_ix], A[i]
            cnt += 1

    print(*A, sep=' ')
    print(cnt)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    select_sort(A, N)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
lst = list(map(int,input().split()))
count = 0
for i in range(0,n):
    flag = 0
    minj = i
    for j in range(i,n):
        if lst[j] < lst[minj]:
            minj = j
            flag = 1
    lst[i],lst[minj] = lst[minj],lst[i]
    if flag == 1:
        count = count + 1
tmp_lst = map(str,lst)
print(' '.join(tmp_lst))
print(count)

Solution (Python):




N = int(input())
A = list(map(int, input().split())) 


def selectionSort(A, N):
    e = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            e += 1
            
    print(" ".join(map(str, A)))
    print(e)
    
selectionSort(A, N)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
counter=0
for i in range(n):
    minj=i
    for j in range(i,n):
        if A[j] < A[minj]:
            minj=j
    if i!=minj:
        tmp=A[i]
        A[i]=A[minj]
        A[minj]=tmp
        counter+=1
for k in range(len(A)):
    if k != len(A)-1:
        print(A[k],end=' ')
    else:
        print(A[k])
print(counter)

Solution (Python):
N = int(input())

num_list = list(map(int,input().split()))

cnt = 0

for i in range(N):
    minj = i
    for j in range(i,N):
        if num_list[j] < num_list[minj]:
            minj = j
    if i != minj:
        num_list[i],num_list[minj] = num_list[minj],num_list[i]
        cnt+=1
        
print(*num_list)
print(cnt)

Solution (Python):
def selectionSort(A, N):
    cnt = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
           cnt += 1
           tmp = A[i]
           A[i] = A[minj]
           A[minj] = tmp
    print(*A)
    print(cnt)
    
n = int(input())
a = list(map(int, input().split()))

selectionSort(a, n)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
count=0

for i in range(N):
    minj=i
    for j in range(i,N):
        if(A[j]<A[minj]):
            minj=j
    v=A[minj]
    A[minj]=A[i]
    A[i]=v
    if(minj!=i):
        count+=1
s=" ".join(map(str,A))
print(s)
print(count)

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
count=0
for i in range(N):
    min=i
    for j in range(i,N):
        if A[j] < A[min]:
            min=j
    if i<min:
        count+=1
        A[i],A[min]=A[min],A[i]
for k in range(N):print(A[k],end=' \n'[k+1==N])
print(count)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
cntswap = 0

for i in range(0,N):
    minj = i
    for j in range(i,N):
        if A[minj] > A[j]:
            minj = j
    if i != minj:
        temp = A[i]
        A[i] = A[minj]
        A[minj] = temp
        cntswap += 1

for i in range(0, N-1):
    print(A[i], '', end='')
print(A[N-1])
print(cntswap)

Solution (Python):
def select(a,n):
	ct=0
	for i in range(n-1):
		minv=i
		for j in range(i+1,n):
			if a[j]<a[minv]:
				minv=j
		t=a[i]
		a[i]=a[minv]
		a[minv]=t
		if a[i]!=a[minv]:
			ct+=1
	return a,ct

n=int(input())
table=list(map(int,input().split()))
b,c=select(table,n)
print(*b)
print(c)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int,input().split()))
    res = 0
    for i in range(n):
        minj = i
        for j in range(i+1,n):
            if a[j] < a[minj]:
                minj = j
        if minj != i:res+=1
        a[i],a[minj] = a[minj],a[i]
    print (' '.join(map(str,a)))
    print (res)

if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())
A = list(map(int, input().split()))

cnt = 0
for i in range(N):
    min_idx = i
    
    for j in range(i, N):
        if A[j] < A[min_idx]:
            min_idx = j

    if i != min_idx:
        A[i], A[min_idx] = A[min_idx], A[i]
        cnt += 1

print(*A)
print(cnt)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
sw = 0
for i in range(n):
    minj = i
    for j in range(i+1,n):
        if a[j] < a[minj]: minj = j
    if i != minj:
        a[i],a[minj] = a[minj],a[i]
        sw += 1
print(" ".join(map(str,a)))
print(sw)

Solution (Python):
N = int(input())
table = list(map(int,input().split()))
count = 0
for i in range(N):
    minj = i
    for j in range(i,N):
        if table[j] <table[minj]:
            minj = j
    table[i],table[minj] = table[minj],table[i]
    if i != minj:
        count += 1

print(" ".join(map(str,table)))
print(count)

Solution (Python):
n = int(input())
*A, = map(int, input().split())
ans = 0
for i in range(n):
    j = A[i:].index(min(A[i:])) + i
    A[i], A[j] = A[j], A[i]
    if i != j:
        ans += 1
print(*A)
print(ans)

Solution (Python):
def selectionSort(A, N):
    c = 0
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        if A[i] != A[minj]:
            A[i],A[minj] = A[minj],A[i]
            c += 1
    return A,c
num = int(input())
li1 = [int(e) for e in input().split()]
li2 = selectionSort(li1,num)
print(*li2[0],sep=" ")
print(li2[1])

Solution (Python):
def select_sort(n, a):
  count = 0
  for i in range(n):
    minj = i
    for j in range(i, n):
      if a[j] < a[minj]:
        minj = j
    if i != minj:
      a[i], a[minj] = a[minj], a[i]
      count += 1
  print(*a)
  print(count)

select_sort(int(input()), [int(i) for i in input().split()])

Solution (Python):
n = int(input())
numL = [0 for i in range(n)]

x = input()
for i in range(n):
    numL[i] = int(x.split()[i])

ctr = 0
for i in range(n-1):
    min = i
    for j in range(i+1,n):
        if numL[j] < numL[min]:
            min = j
    if min == i:
        pass
    else:
        ctr += 1
        tmp = numL[i]
        numL[i] = numL[min]
        numL[min] = tmp

print(*numL)
print(ctr)

Solution (Python):
def selectionSort(A,N):

  count = 0
  for i in range(len(A)):
    min_pos = i
    for j in range(i, len(A)):
      if A[j] < A[min_pos]:
        min_pos = j
    if min_pos != i:
      A[i], A[min_pos] = A[min_pos], A[i]
      count += 1
  return A, count


N = int(raw_input())
A = map(int, raw_input().split())

A, count = selectionSort(A,N)
print ' '.join(map(str, A))
print count

Solution (Python):
N = int(input())
A  = input().split()
A = [int(x) for x in A]

c = 0 
for i in range(N):
    minj = i
    for j in range(i,N):
        if A[j] < A[minj]:
            minj = j
    if i != minj:
        c +=1
        v = A[i]
        A[i] = A[minj]
        A[minj] = v

A = [str(x) for x in A]
print(" ".join(A))
print(c)

Solution (Python):
def selection_sort(A, N):
    cnt = 0
    for i in range(N):
        min_index = i
        for j in range(i, N):
            if A[j] < A[min_index]:
                min_index = j
        if i != min_index:
            A[i], A[min_index] = A[min_index], A[i]
            cnt += 1
    print(' '.join(list(map(str, A))))
    print(cnt)


N = int(input())
A = list(map(int, input().split()))
selection_sort(A, N)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ret = 0
for i in range(n):
    min_i = i
    for j in range(i+1,n):
        if a[j] < a[min_i]:
            min_i = j
    if i!= min_i:
        ret += 1
        a[i],a[min_i]=a[min_i],a[i]
print(" ".join(map(str,a)))
print(ret)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

count = 0
for i in range(n):
    minj = i
    for j in range(i + 1, n):
        if (A[minj] > A[j]):
            minj = j
    if (i != minj):
        A[i], A[minj] = A[minj], A[i]
        count += 1

print(' '.join(map(str, A)))
print(count)

Solution (Python):
def show(nums):
    for i in range(len(nums)):
        if i!=len(nums)-1:
            print(nums[i],end=' ')
        else:
            print(nums[i])

def selection_sort(A, N):
    num = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if minj != i:
            A[i], A[minj] = A[minj], A[i]
            num += 1

    show(A)
    print(num)



if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split(' ')))
    selection_sort(A, N)

Solution (Python):
from typing import MutableSequence


def selection_sort(a_list: MutableSequence, n: int) -> int:
    """単純選択ソート"""
    sw_cnt = 0
    for i in range(n - 1):
        min = i
        for j in range(i + 1, n):
            if a_list[j] < a_list[min]:
                min = j

        if i != min:
            sw_cnt += 1

        a_list[i], a_list[min] = a_list[min], a_list[i]

    print_list = [str(i) for i in a_list]
    print(' '.join(print_list))
    print(sw_cnt)


if __name__ == '__main__':
    n = int(input())
    input_list = [int(x) for x in input().split()]

    selection_sort(input_list, n)

Solution (Python):
def swap(A, i, j):
    temp = A[i]
    A[i] = A[j]
    A[j] = temp

def selection(A):
    N = len(A)
    count = 0
    for i in range(N):
        min_j = i
        for j in range(i, N):
            if A[j] < A[min_j]:
                min_j = j
        if (min_j != i):
            swap(A, i, min_j)
            count += 1
    print(" ".join(map(str, A)))
    print(count)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    selection(A)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))


def selectionSort(a, n):
    ans = 0
    for i in range(n):
        minj = i
        for j in range(i, n):
            if a[j] < a[minj]:
                minj = j

        a[i], a[minj] = a[minj], a[i]
        if i != minj:
            ans += 1

    print(*a)
    print(ans)


selectionSort(l, n)

Solution (Python):
def selectionSort(A,N):
    global cnt
    
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            cnt = cnt + 1
    return A
    
    
n = int(input())
R = list(map(int,input().split()))
cnt = 0
R = selectionSort(R,n)
print(*R)
print(cnt)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
swap = 0
for i in range(N - 1):
    _i = i
    _min = A[i]
    for j in range(i + 1, N):
        if A[j] < _min:
            _i = j
            _min = A[j]
    if i != _i:
        swap += 1
        A[i], A[_i] = A[_i], A[i]
print(*A)
print(swap)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))

def selection(a:list, n:int) -> None:
    if not isinstance(a, list):
        return None

    cnt=0
    for i in range(n):
        minj=i
        for j in range(i, n):
            if a[j] < a[minj]:
                minj=j
        a[i], a[minj] = a[minj], a[i]

        if i != minj: cnt+=1

    print(" ".join(map(str, a)))
    print(cnt)

selection(a, n)

Solution (Python):
import sys
import math
from typing import Tuple, List
input = sys.stdin.readline

def  print_vec (A: list):
    print (" ".join(map (str, A)))

def swap (A: List, i: int, j: int) -> None:
    temp = A [i]
    A [i] = A [j]
    A [j] = temp
 

def selection_sort(A: List) -> Tuple[List, int]:
    swap_cout = 0
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j] < A[mini]:
                mini = j
        if (mini != i):
            swap(A, i, mini)
            swap_cout+=1
    return (A, swap_cout)


if __name__ == "__main__":
    n = int(input())
    vec = list (map (int, input ().split ()))
    result =  selection_sort(vec)
    print_vec (result [0])
    print(result [1])

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
cnt = 0
for i in range(N):
    minj = i
    for j in range(i+1, N):
        if A[j] < A[minj]:
            minj = j
    if minj != i:
        tmp = A[i]
        A[i] = A[minj]
        A[minj] = tmp
        cnt += 1
A = [str(a) for a in A]
print(" ".join(A))
print(cnt)

Solution (Python):
N = int(input())
seq = list(map(int, input().split()))
count = 0

for i in range(len(seq)):
    min = i
    for j in range(i, len(seq)):
        if seq[j] < seq[min]:
            min = j
    if seq[i] != seq[min]:
        seq[i], seq[min] = seq[min], seq[i]
        count += 1
    if seq == sorted(seq):
        print(*seq)
        print(count)
        break

Solution (Python):
N = int(input())
data = list(map(int, input().split()))
count = 0

for i in range(N):
    min = i
    for j in range(i, N):
        if data[j] < data[min]:
            min = j
    if min != i:
        data[i], data[min] = data[min], data[i]
        count += 1
            
print("%d" %data[0], end="")
for i in range(1, N):
    print(" %d" %data[i], end="")
print()
print(count)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

cnt = 0
for i in range(n):
    minj = i
    for j in range(i+1,n):
        if a[j]<a[minj]:
            minj = j
    if minj!=i:
        a[i], a[minj] = a[minj], a[i]
        cnt+=1

print(*a)
print(cnt)

Solution (Python):
N = int(input()) 
A = list(map(int, input().split())) 
cnt = 0
for j in range(N-1):
    min_i = j
    for i in range(j, N):
        if A[i] < A[min_i]:
            min_i = i
    if A[j] > A[min_i]:
        v = A[j]
        A[j] = A[min_i]
        A[min_i] = v
        cnt += 1
print(*A)
print(cnt)

Solution (Python):
n = int(input())
l = list(map(int, input().split(" ")))
f = 0
for j in range(n-1):
    m = l[j:].index(min(l[j:]))
    if m != 0:
        l[j], l[m + j] = l[m + j], l[j]
        f += 1
print(*l)
print(f)

Solution (Python):
def selectionsort(a, n):
    count = 0
    for i in range(n):
        min = i
        for j in range(i, n):
            if a[min] > a[j]:
                min = j
        if i != min:
            count += 1
            a[i], a[min] = a[min], a[i]
    return count

N = int(input())
A = list(map(int, input().split()))

c = selectionsort(A, N)
print(*A)
print(c)

Solution (Python):
N = int(input())
A = [int(item) for item in input().split()]

def selectionSort(A, N):
    cnt = 0
    for i in range(N-1):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            cnt += 1
    
    print(*A)
    print(cnt)

selectionSort(A, N)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split(" ")]

count = 0
for i in range(n):
    minv = a[i]
    mini = i
    for j in range(i+1, n, 1):
        if minv > a[j]:
            minv = a[j]
            mini = j
    if i != mini:
        a[i], a[mini] = a[mini], a[i]
        count += 1
print(" ".join([str(i) for i in a]))
print(count)

Solution (Python):
N, *A = map(int, open(0).read().split())

count = 0
for i in range(N):
    min_j = i
    for j in range(i, N):
        if A[j] < A[min_j]: 
            min_j = j
    if min_j != i:
        A[i], A[min_j] = A[min_j], A[i]
        count += 1

print(' '.join([str(a) for a in A]))
print(count)

Solution (Python):
def SelectionSort(A, N):
    count = 0
    for i in range(N):
        flag = 0
        minj = i
        j = i - 1
        for j in range(i,N):
            if A[j] < A[minj]:
                flag = 1
                minj = j
            
        if flag == 1:
            a = A[minj]
            A[minj] = A[i]
            A[i] = a
            count += 1
 
    return(A, count)

N = int(input())
A = list(map(int,input().split()))

A, count = SelectionSort(A,N)
print(' '.join(map(str, A)))
print(count)

Solution (Python):
import sys

def selection_sort(size, numbers):
    swap_count = 0

    for i in range(size):
        minindex = i
        for j in range(i + 1, size):
            if numbers[j] < numbers[minindex]:
                minindex = j

        if i != minindex:
            swap_count += 1
            numbers[i], numbers[minindex] = numbers[minindex], numbers[i]

    return swap_count

def main(stdin=None, stdout=None):
    if stdin is None:
        stdin = sys.stdin
    if stdout is None:
        stdout = sys.stdout

    size = int(stdin.readline().strip())
    numbers = [int(x) for x in stdin.readline().strip().split(" ")]

    swap_count = selection_sort(size, numbers)
    stdout.write(" ".join([str(x) for x in numbers]) + "\n")
    stdout.write(str(swap_count) + "\n")

main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
numSwap = 0

for i in range(n):
    minj = i
    for j in range(i,n):
        if a[j] < a[minj]:
            minj = j
    if minj != i:
        numSwap += 1
        a[i],a[minj] = a[minj],a[i]
a = [str(s) for s in a]
print(' '.join(a))
print(numSwap)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    selectionSort(A, N)


def selectionSort(A, N):
    count = 0
    for i in range(N):
        minj  = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
    
        if i != minj:
            A[i], A[minj] = A[minj], A[i]
            count += 1

    print(*A)
    print(count)


main()

Solution (Python):
a = int(input())
b = list(map(int,input().split()))
A = []


def selectionSort(b,a):
    count = 0
    for i in range(len(b)-1):
        mini = i
        for j in range(i+1,len(b)):
            if b[mini]>b[j]:
                mini = j
        if b[mini]!=b[i]:
            b[i],b[mini]=b[mini],b[i]
            count += 1
    return b,count

A,B = selectionSort(b,a)
print(*A)
print(B)

Solution (Python):



def SelectionSort(N, A):
   count = 0 
   for i in range(0, N-1):
      minj = i
      for j in range(i+1, N): 
         if A[j] < A[minj]:
            minj = j 
      
      if A[minj] < A[i]:
         A[i], A[minj] = A[minj], A[i]
         count+=1
      
   return A, count

N = int(input())
A = list(map(int, input().split())) 
ans, count = SelectionSort(N, A)
print(*ans)
print(count)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
count=0
for i in range(n):
    min=i
    for j in range(i,n):
        if A[j]<A[min]:
            min=j
    if min!=i:
        A[i],A[min]=A[min],A[i]
        count+=1
for i in range(n-1):
    print(A[i],end=" ")
print(A[n-1])
print(count)

Solution (Python):
n = int(input())
arr = [ int(i) for i in input().split(" ")]

cnt = 0
for i in range(len(arr)-1):
  
  minj = i+1
  for j in range(i, len(arr)):
    if arr[j] < arr[minj]:
      minj = j
  
  tmpCur = arr[i]
  tmpMin = arr[minj]
  if tmpCur > tmpMin:
    cnt += 1
    arr[i], arr[minj] = tmpMin, tmpCur

print(" ".join([str(i) for i in arr]))
print(cnt)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
count = 0

for i in range(N):
    minj = i
    for j in range(i,N):
        if A[j] < A[minj]:
            minj = j
    tmp = A[i]
    A[i] = A[minj]
    A[minj] = tmp
    if minj != i:
        count += 1
print(' '.join([str(a) for a in A])) 
print(count)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))

cnt = 0
for i in range(N):
    minj = i
    for j in range(i,N):
        if A[j] < A[minj]:
            minj = j
    if minj != i:
        tmp = A[minj]
        A[minj] = A[i]
        A[i] = tmp
        cnt += 1

print(" ".join([str(s) for s in A]))
print(cnt)

Solution (Python):

input_number = int(input())
input_list = list(map(int, input().split()))
exchange_count = 0


for i in range(input_number):
    min_data = input_list[i]
    min_number = -1
    for j in range(i+1, input_number):
        if min_data > input_list[j]:
            min_data = input_list[j]
            min_number = j
    if min_number != -1:
        input_list[i], input_list[min_number] = input_list[min_number], input_list[i]
        exchange_count += 1


print(" ".join(map(str, input_list)))
print(exchange_count)

Solution (Python):
def selection_sort():
    N = int(input())
    A = [int(_) for _ in input().split()]

    ans = 0

    for i in range(N):
        minj = i 
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        if i != minj:
            ans += 1
    
    print(' '.join(map(str, A)))
    print(ans)
        

selection_sort()

Solution (Python):
def SelectionSort(seq):
    swp_cnt = 0
    
    for i in range(0, len(seq)):
        idx = i

        for j in range(i, len(seq)):
            if seq[idx] > seq[j]:
                idx = j

        if idx != i:
            seq[i], seq[idx] = seq[idx], seq[i]        
            swp_cnt += 1

    print(*seq)
    print(swp_cnt)

def main():
    n = input()
    seq = [int(a) for a in input().split()]
    SelectionSort(seq)

main()

Solution (Python):






def SelectionSort(A: list):
    number_of_actual_swaps = 0
    for i in range(0, len(A)):
        minj = i
        for j in range(i, len(A)):
            if A[j] < A[minj]:
                minj = j

        A[i], A[minj] = A[minj], A[i]
        if i != minj:
            number_of_actual_swaps += 1

    print(*A, sep=" ")
    print(number_of_actual_swaps)


def main():
    length = int(input())
    A = [int(e) for e in input().split()]
    SelectionSort(A)


if __name__ == "__main__":
    main()

Solution (Python):
def selection(n, data):
    __count = 0
    for i in range(n):
        min_i = i
        for j in range(i+1, n):
            if data[min_i] > data[j]:
                min_i = j
        tmp = data[i]
        data[i] = data[min_i]
        data[min_i] = tmp
        if min_i != i:
            __count += 1

    return data, __count

def show(data, count):
    for i in range(len(data)):
        if i != (len(data)-1):
            print(data[i], end = " ")
        else:
            print(data[i])
    print(count)

if "__main__" == __name__:
    n = int(input())
    data = list(map(int, input().rsplit()))
    data, count = selection(n, data)
    show(data, count)

Solution (Python):
def show(A):
    N = len(A)
    for i in range(N):
        if i :
            print(' ', end = '')
        print(A[i], end = '')
    print()

def selectionSort(A, N):
    exchange = 0
    for i in range(N):
        min_j = i
        for j in range(i, N):
            if A[j] < A[min_j]:
                min_j = j
        if min_j != i:
            A[i], A[min_j] = A[min_j], A[i]
            exchange += 1
    show(A)
    print(exchange)

N = int(input())
A = [int(i) for i in input().split()]

selectionSort(A, N)

Solution (Python):
def printData(data) :
    for i, value in enumerate(data) :
        if i > 0 :
            print(" ", end = "")
        print(value, end = "")
    print()
    
def selectionSort(data, N) :
    count = 0
    for i in range(0, N) :
        sortIdx = i
        for j in range(i + 1, N) :
            if data[sortIdx] > data[j] :
                sortIdx = j
        if sortIdx != i :
            buf = data[sortIdx]
            data[sortIdx] = data[i]
            data[i] = buf
            count += 1
            
    printData(data)
    print(count)
    
N = int(input())
data = [int(char) for char in input().split()]
selectionSort(data, N)

Solution (Python):
def SelectionSort(A, N):

    changenum = 0

    for i in range(0, N):
        minj = i

        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
                
        if minj != i:
            changenum += 1
            A[minj], A[i] = A[i], A[minj]
        
    
    print(' '.join([str(x) for x in A]))
    print(changenum)

N = int(input())
A = [int(x) for x in input().split()]

SelectionSort(A, N)

Solution (Python):


n = int(input())

A = list(map(int,input().split()))

count = 0
for i in range(0,n):
    minj = i
    for j in range(i,n):
        if A[j] < A[minj]:
            minj = j

    if i != minj:
        count += 1
        A[i],A[minj] = A[minj],A[i]


print(*A)
print(count)

Solution (Python):
N = int(input())
* A, = map(int, input().split())
count = 0
for i in range(N):
    minj = i
    for j in range(i+1, N):
        if A[j] < A[minj]:
            minj = j
    A[i], A[minj] = A[minj], A[i]
    if i != minj:
        count += 1
print(*A)
print(count)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

cnt = 0

for i in range(n):
    minj = i
    for j in range(i, n):
        if a[j] < a[minj]:
            minj = j
    a[i], a[minj] = a[minj], a[i]
    if i != minj:
        cnt += 1
print(" ".join(map(str, a)))
print(cnt)

Solution (Python):
def selectionSort(A, N):
    swap_count = 0
    for i in range(N):
        minj = i
        for j in range(i + 1, N):
            if A[j] < A[minj]:
                minj = j
        if minj != i:
            A[minj], A[i] = A[i], A[minj]
            swap_count += 1
    return swap_count


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    count = selectionSort(A, N)
    print(' '.join(map(str, A)))
    print(count)

Solution (Python):
def selection(A,N):
    global cnt
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            A[i],A[minj] = A[minj],A[i]
            cnt += 1
    return A

n = int(input())
a = [int(s) for s in input().split()]
cnt = 0
print(" ".join(map(str,selection(a,n))))
print(cnt)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

def selection_sort(A, N):
    count = 0
    for i in range(0, N):
        min_j = i
        for j in range(i, N):
            if A[j] < A[min_j]:
                min_j = j
        if min_j != i:
            count += 1
        A[i], A[min_j] = A[min_j], A[i]
    return A, count

A, count = selection_sort(A, N)
print(' '.join(map(str, A)))
print(count)

Solution (Python):

def selection_sort(a,n):
    count = 0
    for i in range(n):
        minj = i
        m = n-1-i+1
        for j in range(m):
            k = i + j
            if a[k] < a[minj]:
                minj = k
        
        if minj!=i:
            minnum = a[minj]
            a[minj] = a[i]
            a[i] = minnum
            count += 1
    return a, count

n = int(input())
a = list( map(int, input().split()) )

arr, count = selection_sort(a, n)
res = str(arr[0])
for i in range(n-1):
    res += " " + str(arr[i+1])

print(res)
print(count)

Solution (Python):
def main():
    N = int(input())
    a_lists = list(map(int, input().split()))
    cnt = 0
    for i in range(N):
        min_j = i
        for j in range(i, N):
            if a_lists[j] < a_lists[min_j]:
                min_j = j
        if min_j == i:
            continue
        a_lists[i], a_lists[min_j] = a_lists[min_j], a_lists[i]
        cnt += 1
    print(' '.join(map(str, a_lists)))
    print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
def selection_rort(a, n):
    count = 0
    for i in range(n):
        
        minj = i
        for j in range(i, n):
            if a[j] < a[minj]:
                minj = j
        a[minj], a[i] = a[i], a[minj]
        if minj != i:
          count += 1
        
    return a, count

n = int(input())
a = list(map(int, input().split()))

a, count = selection_rort(a, n)
print(" ".join(map(str,a)))
print(count)

Solution (Python):
def selection_sort(A, N):
    c = 0
    for i in range(N-1):
        minj = A[i+1:].index(min(A[i+1:])) + i+1
        if A[i] > A[minj]:
            A[i], A[minj] = A[minj], A[i]
            c += 1
    return A, c

N = int(input())
A = list(map(int, input().split()))
A, c = selection_sort(A, N)
print(' '.join(map(str, A)))
print(c)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

trade = 0
for i in range(n):
    minj = i 
    for j in range(i, n):
        if a[j] < a[minj]:
            minj = j
    if i != minj:
        trade += 1
    a[i], a[minj] = a[minj], a[i]
    
print(' '.join(map(str, a)))
print(trade)

Solution (Python):

N = int(input())
lst = list(map(int,input().split()))
cnt = 0
for i in range(N):
    minj = i
    for j in range(i, N):
        if (lst[j] < lst[minj]):
            minj = j
    lst[i],lst[minj] = lst[minj],lst[i]
    if (i != minj):
        cnt += 1
print(" ".join(list(map(str, lst))))
print(cnt)