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 = list(int(x) for x in input().split())
count = 0
for i in range(N):
  min_a = i
  for j in range(i,N):
    if a[j] < a[min_a]:
      min_a = j
  if min_a != i:
    count += 1
  tmp = a[i]
  a[i] = a[min_a]
  a[min_a] = tmp

for k in range(N):
  if k == N-1:
    print(a[k],end ="")
  else:
    print(a[k],end =" ")
    
print()
print(count)

Solution (Python):



def printList(array):
    print(' '.join(map(str, array)))



def selectionSort(A, N):
    swapCount = 0
    for index in range(0, N):
        minj = index
        for j in range(index, N):
            if A[j] < A[minj]:
                minj = j

        if index != minj:
            swapCount += 1

        A[index], A[minj] = A[minj], A[index]

    printList(A)
    print(str(swapCount))


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

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))
change = 0

for i in range(n):
    minj = i
    for j in range(i, n):
        if arr[j] < arr[minj]:
            minj = j
    else:
        if i != minj:
            arr[i], arr[minj] = arr[minj], arr[i]
            change += 1

def print_space(li):
    for i in range(len(li)-1):
        print(li[i], end=' ')
    else:
        print(li[-1])

print_space(arr)
print(change)

Solution (Python):
def selectionSort(A, N):
    cnt = 0
    for i in range(N):
        minJ = i
        for j in range(i, N):
            if A[minJ] > A[j]:
                minJ = j
        if A[i] != A[minJ]:
            tmp = A[i]
            A[i] = A[minJ]
            A[minJ] = tmp
            cnt += 1
    return A, cnt


def resolve():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans, cnt = selectionSort(A, N)
    print(*ans)
    print(cnt)


resolve()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
cnt = 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 i != min_j:
        A[i], A[min_j] = A[min_j], A[i]
        cnt += 1
print(*A)
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
    if i!=minj:
        count+=1
    R=A[i]
    A[i]=A[minj]
    A[minj]=R
Z=[str(a) for a in A]
Z=" ".join(Z)
print(Z)

print(count)

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

for i in range(N-1):
    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
print(*A)
print(count)

Solution (Python):
def min_index(A):
    index = 0
    m = A[0]
    for i in range(1,len(A)):
        if A[i] < m:
            m = A[i]
            index = i
    return index

def selectionsort(A,N):
    count = 0
    for i in range(N-1):
        j = min_index(A[i+1:])
        if A[i] > A[i+j+1]:
            
            count += 1
            A[i],A[i + min_index(A[i+1:]) + 1] = A[i + min_index(A[i+1:]) + 1],A[i]
    return A,count

if __name__ == '__main__':
    N = int(input())
    A = [int(i) for i in input().split()]
    ans,count = selectionsort(A,N)
    for i in range(N):
        if i != N - 1:
            print(ans[i],end = " ")
        else:
            print(ans[i])
    print(count)

Solution (Python):


from sys import stdin
input = lambda: stdin.readline().rstrip()

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

cnt = 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 i != minj:
        w = A[i]
        A[i] = A[minj]
        A[minj] = w
        cnt = cnt + 1

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

Solution (Python):
def selection_sort(A,N):
    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
    return A, cnt

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

A,cnt = selection_sort(A,N)
print(*A)
print(cnt)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
import functools

def SelectionSort(A):
    cnt = 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:
            tmp = A[i]
            A[i] = A[mini]
            A[mini] = tmp
            cnt += 1
    return cnt
n = int(input())
A = list(map(int,input().split()))
cnt = SelectionSort(A)
print(*A)
print(cnt)

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 i != minj:
        a[i], a[minj] = a[minj], a[i]
        cnt += 1

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

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

Solution (Python):
n = int(input())
l = []
for i in map(int, input().split()):
    l.append(i)

'''
n = 10
l = [9,5,10,3,6,7,4,1,2,8]
'''

start_index = 0
swap_cnt = 0

for j in range(start_index, n):
    if len(l[start_index:n]) == 1:
        break
    else:
        tmp = l[start_index]
        min_value = l[start_index]
        min_index = start_index

        for idx in range(start_index,n):
            if min_value > l[idx]:
                min_value = l[idx]
                min_index = idx

        l[start_index] = min_value
        l[min_index] = tmp

        if min_value != tmp:
            swap_cnt += 1

        start_index += 1

print(' '.join(map(str,l)))
print(swap_cnt)

Solution (Python):
from typing import List, Tuple


def selection_sort(A: List[int]) -> Tuple[List[int], int]:
    count: int = 0

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

    return A, count


def main():
    _ = input()
    A: List[int] = list(map(int, input().split()))

    lst, count = selection_sort(A)
    print(*lst, sep=" ")
    print(count)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    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:
            A[i], A[minj] = A[minj], A[i]
            cnt+=1

    print(*A)
    print(cnt)

if __name__ == '__main__':
    resolve()

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

Solution (Python):
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 minj != i:
            v = A[i]
            A[i] = A[minj]
            A[minj] = v
            count += 1
    print(" ".join(map(str,A)))
    print(count)
    
n = int(input())
numlist = [int(x) for x in input().split()]

selectionSort(numlist,n)

Solution (Python):
n = int(input())
R = [int(x) for x in input().split()]
def selected_sort(a,n):
    count=0
    judge=False
    for i in range(0,n-1):
        minj=i
        for j in range(i,n):
            if a[j]<a[minj]:
                minj=j
                judge=True
        a[i],a[minj]=a[minj],a[i]
        if judge:
            count+=1
        judge=False
    print(*a)
    print(count)
        

selected_sort(R,n)

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
    else:
        if minj != i:
            A[i],A[minj] = A[minj],A[i]
            cnt += 1
print(" ".join(map(str,A)))
print(cnt)

Solution (Python):
n = int(input())
A = [int(x) for x in 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 i != minj:
        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 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)

Solution (Python):
num = int(input(""))
seqs = list(map(int,input().split())) 
count = 0
    
for i in range(num): 
    
    minIndex = i 
    
    
    for j in range(i,num):
    
        if seqs[j] < seqs[minIndex]:
            minIndex = j
            
    
    
    if minIndex != i:
        seqs[i],seqs[minIndex]=seqs[minIndex],seqs[i]
        count+=1
    
print(" ".join(map(str, seqs)))
print(count)

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

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

indexMin = 0
count = 0


for start in range(n):
    indexMin = s[start:].index(min(s[start:])) + start
    s[start], s[indexMin] = s[indexMin], s[start]
    if start != indexMin:
        count+=1

print(*s)
print(count)

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
    if minj != i:
        dummy = A[i]
        A[i] = A[minj]
        A[minj] = dummy
        count +=1
for i in range(N-1):
    print(f"{A[i]}",end=" ")
print(f"{A[N-1]}\n{count}")

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

count = 0
for a in range(len(A)-1):
    index_min = A[(a+1):].index(min(A[(a+1):]))+a+1
    
    if A[a] > A[index_min]:
        A[a],A[index_min] = A[index_min],A[a]
        count += 1
        
print(*A)
print(count)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
    mini=i
    for j in range(i,n):
        if a[mini]>a[j]:
            mini=j
    if mini!=i:
        a[i],a[mini]=a[mini],a[i]
        cnt+=1
print(*a)
print(cnt)

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


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

for i in range(N):
    if i != 0:
        print(" ", end="")
    print(A[i], end="")

print()
print(cnt)

Solution (Python):
import math
import itertools

def main():
  n = int(input())
  A = list(map(int, input().split()))
  len_A = len(A)
  times = 0

  for i in range(len_A):
    min = i
    for j in range(i+1, len_A):
      if A[j] < A[min]:
        min = j
    
    if min != i:
      tmp = A[min]
      A[min] = A[i]
      A[i] = tmp
      times += 1

  print(*A)
  print(times)

if __name__ == '__main__':
  main()

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 A[i] != A[minj]:
            cnt += 1
        A[i], A[minj] = A[minj], A[i]
    print(*A)
    print(cnt)


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

selectionSort(A, N)

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

selection_sort(array,num)

Solution (Python):
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:        
            ho = A[i]
            A[i] = A[minj]
            A[minj] = ho
            count += 1
    return A, count

n = int(input())
a = [ int(i) for i in input().split()]
b , count = selectionSort(a,n)
for i in range(len(b)):
    if i == len(b)-1:
        print(b[i])
    else:
        print(b[i],end=' ')            
print(count)

Solution (Python):
n = int(input())
As = input().split()
A = [int(i) for i in As]
c = 0

for i in range(n-1):
    mini = i
    j = i
    while n > j:
        if A[j] < A[mini]:
            mini = j
        j += 1
    if i != mini:
        w = A[i]
        A[i] = A[mini]
        A[mini] = w
        c += 1

for i in range(n-1):
    print("{} ".format(A[i]), end="")
print(A[n-1])
print(c)

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

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

result = [str(i) for i in A]
print(' '.join(result))
print(cnt)

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

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

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:
        a[i], a[minj] = a[minj], a[i]
        count += 1
    
print(" ".join([str(num) for num in a]))
print(count)

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

icnt = 0
for i in range(0, len(a)):
	imin = i
	for j in range(i + 1, len(a)):
		if a[j] < a[imin]:
			imin = j
	if imin != i:
		a[i], a[imin] = a[imin], a[i]
		icnt = icnt + 1

print(' '.join([str(n) for n in a]))
print(icnt)

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

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
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[x],end=' ') for x in range(N-1)];print(A[N-1]);print(cnt)

Solution (Python):
def selectionSort(A, N):
    count = 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:
            temp = A[i]
            A[i] = A[minj]
            A[minj] = temp
            count += 1
    return count

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

Solution (Python):
def selectionSort(A, n):
    k = 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:
            k += 1

    L=[str(a) for a in A]
    L=" ".join(L)
    print(L)
    print(k)



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(0, N):
    min_A = A[i]
    for j in range(i, N):
        if A[j] < min_A:
            min_A = A[j]
            num = j
    if min_A < A[i]:
        v = A[i]
        A[i] = min_A
        A[num] = v
        count += 1

s = [str(a) for a in A]
s = " ".join(s)
print(s)
print(count)

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,1):
        if a[minj] > a[j]:
            minj = j
    if minj != i:
        a[minj], a[i] = a[i], a[minj]
        count += 1
print(*a)
print(count)

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
    if (minj != i):
        (a[i], a[minj]) = (a[minj], a[i])
        count += 1

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

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

swapcnt = 0

def bubbleSort(A):
  global N,swapcnt
  for i in range(N):
    for j in  range(N-1,i,-1):
      if A[j] < A[j-1]:
        x = A[j]
        A[j] = A[j-1]
        A[j-1] = x
        swapcnt += 1

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


selectionSort(A)
strA = [str(a) for a in A]
print(" ".join(strA))
print(swapcnt)

Solution (Python):
def selection_sort(lst, n):
    count = 0
    for i in range(n - 1):
        minj = i
        for j in range(n - i):
            if lst[minj] > lst[j + i]:
                minj = j + i
        if minj != i:        
            tmp = lst[i]
            lst[i] = lst[minj]
            lst[minj] = tmp
            count += 1
    map_lst = map(str,lst)
    print(" ".join(map_lst))
    print(count)

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

selection_sort(num_list, n)

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

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

print(" ".join(map(str,A)))
print(change)

Solution (Python):
n = int(input())
a = []
a = input().split()
a = list(map(int,a))
num = 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]
        num = num + 1

print(*a)
print(num)

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

for i in range(N-1):
    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]
        count+=1
print(*A)
print(count)

Solution (Python):
def selectionSort(sort_list):
    count = 0

    for i in range(0, len(sort_list)):
        minj = i

        for j in range(i, len(sort_list)):
            if sort_list[j] < sort_list[minj]:
                minj = j

        if minj != i:
            tmp = sort_list[i]
            sort_list[i] = sort_list[minj]
            sort_list[minj] = tmp
            count += 1

    print(' '.join([str(i) for i in sort_list]))
    print(count)


if __name__ == "__main__":
    N = int(input())
    sort_list = [int(i) for i in input().split()]

    selectionSort(sort_list)

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
    if minj != i:
        count += 1
        a[i],a[minj] = a[minj],a[i]
print(*a)
print(count)

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

def trace():
    for i in range(len(R)):
        if i != len(R) - 1:
            print(R[i],end=' ')
        else:
            print(R[i])

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

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


trace()
print(count)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
times = 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]
        times += 1

print(" ".join(map(str, A)))
print(times)

Solution (Python):
N = int(input())
A = list(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

        temp = A[i]
        A[i] = A[minj]
        A[minj] = temp
        if i != minj:
            cnt += 1

    return(A, cnt)

out_A, cnt_sort = selectionSort(A,N)

out_A_str = list(map(str, out_A))
print(" ".join(out_A_str))
print(str(cnt_sort))

Solution (Python):
n=int(input())
nums=list(map(int,input().split()))
count=0
for i in range(n):
    
    minj=i
    minv=nums[minj:].index(min(nums[minj:]))+minj
    if minv!=minj:
        count+=1

    nums[minj],nums[minv]=nums[minv],nums[minj]
    

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

        else:
            print(nums[j])

show(nums)
print(count)

Solution (Python):


def selection_sort(A, N):
    sort_count = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j]<A[minj]:
                minj = j
        if not minj==i:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            sort_count += 1
    return A, sort_count


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


ans_list, ans_count = selection_sort(a_nums, N)
print(" ".join(list(map(str, ans_list))))
print(ans_count)

Solution (Python):


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

def selectionSort(A):
	n = len(A)
	cnt = 0
	for i in range(n - 1):
		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
	return cnt

cnt = selectionSort(A)

print(*A)
print(cnt)

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

counter=0
for i in range(0,N-1):
    min_,min_index=min(S[i:]),S[i:].index(min(S[i:]))+i
    first_element,first_element_index=S[i],i
    
    if min_index!=first_element_index:
        counter+=1
        S[first_element_index],S[min_index]=S[min_index],S[first_element_index]
        
print(*S)
print(counter)

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

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

print(*A)
print(cnt)

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 i != minj:
        cnt += 1
    a[i],a[minj] = a[minj],a[i]
print(*a)
print(cnt)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))
cnt = 0
for i in range(len(arr)):
    Min = i
    for j in range(i, len(arr)):
        if arr[j] < arr[Min]:
            Min = j
    if i != Min:
        arr[i], arr[Min] = arr[Min], arr[i]
        cnt += 1
print(*arr)
print(cnt)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
cnt=0
for i in range(N-1):
    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:
        cnt+=1
print(*A)
print(cnt)

Solution (Python):
def selectionSort(A,N):
    c = 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):
            t = A[i]
            A[i] = A[minj]
            A[minj] = t
            c+=1

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

if __name__=="__main__":
    n = int(input())
    l = [int(x) for x in input().split()]
    selectionSort(l,n)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
c = 0
flag = 0
for i in range(n):
    minv = i
    for j in range(i+1, n):
        if a[j]<a[minv]:
            minv = j
            flag = 1
    c += flag
    flag = 0
    a[i], a[minv] = a[minv], a[i]
print(*a)
print(c)

Solution (Python):
from copy import deepcopy

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

A = deepcopy(a)
j = 0
cnt = 0
for i in range(n-1):
    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(*A)
print(cnt)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(n-1):
    min = i+1
    for j in range(i+1,n):
        if a[min] > a[j]:
            min = j
    if a[i] > a[min]:
        a[i],a[min] = a[min],a[i]
        cnt += 1
for i in range(n):
    if i != n-1:
        print(a[i], end=' ')
    else:
        print(a[i])
print(cnt)

Solution (Python):
def selection(A,N):
    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:
            A[i],A[minj]=A[minj],A[i]
            count += 1
    return count 

n = int(input())
a = list(map(int,input().split()))
count=selection(a,n)
print(' '.join(map(str,a)))
print(count)

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

for i in range(n - 1):
    minv = A[i]
    minv_idx = i
    for k in range(i + 1, n):
        if minv > A[k]:
            minv = A[k]
            minv_idx = k
    if i != minv_idx:
        A[i], A[minv_idx] = minv, A[i]
        c += 1

print(*A)
print(c)

Solution (Python):
def selectionsort(a, n):
    n_exchange = 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 a[i] != a[min_j]:
            n_exchange += 1

        a[i], a[min_j] = a[min_j], a[i]

    return a, n_exchange


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

sorted_a, n_exchange = selectionsort(a, n)

print(' '.join([str(x) for x in sorted_a]))
print(n_exchange)

Solution (Python):
def SelectionSort(l):
  countSwap = 0
  for i in range(len(l)):
    minj = i
    for j in range(i, len(l)):
      if l[j] < l[minj]:
        minj = j
    if minj == i:
      continue
    else:
      temp = l[i]
      l[i] = l[minj]
      l[minj] = temp
      countSwap += 1
  print(" ".join(map(str, l)))
  print(countSwap)

N = input()
l = list(map(int, input().split()))
SelectionSort(l)

Solution (Python):
from sys import stdin
input = stdin.readline

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


def p(N):
    for i in range(len(N)):
        if i == len(N) - 1:
            print(N[i])
        else:
            print(N[i], end=" ")


ans = 0

for i in range(N):
    m = i
    for j in range(i + 1, N):
        if A[j] < A[m]:
            m = j
    if m != i:
        ans += 1
        A[m], A[i] = A[i], A[m]

p(A)
print(ans)

Solution (Python):


n = int(input())
l = list(map(int, input().split()))
c = 0
for i in range(n):
    minj = i + l[i:].index(min(l[i:]))
    if minj != i:
        l[i], l[minj] = l[minj], l[i]
        c += 1
print(' '.join(map(str, l)))
print(c)

Solution (Python):



def selectionSort(A, N):
    cnt = 0
    for i in range(0, 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


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

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

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

swap=0
for i in range(len(lst)):
    min_i = i
    for j in range(i+1,len(lst)):
        if lst[j] < lst[min_i]:
            min_i = j
    lst[i],lst[min_i] = lst[min_i],lst[i]
    if lst[i]!=lst[min_i]:
        swap+=1

print(' '.join(map(str,lst)))
print(swap)

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

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

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


count = 0

for i in range(n):
    m = i
    for j in range(i+1, n):
        if a[j] < a[m]:
            m = j
    a[i], a[m] = a[m], a[i]
    if i != m:
        count += 1

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

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

count = 0

for i in range(n):
    min_index = i
    for j in range(i, n):
        if l[min_index] > l[j]:
            min_index = j
    if min_index != i:
        l[i], l[min_index] = l[min_index], l[i]
        count += 1

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

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

def selectionSort(A,N):
    num=0
    for i in range(N-1):
        minj=i
        for j in range(i,N):
            if A[minj] > A[j]:
                minj=j
        if minj != i:
            tmp=A[i]
            A[i]=A[minj]
            A[minj]=tmp
            num += 1
    return A,num

A,N=selectionSort(A,N)
print(*A)
print(N)