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(map(int, input().strip().split()))
count = 0
for i in range(n):
    mini = i
    for j in range(i, n):
        if a[j] < a[mini]:
            mini = j
    if i != mini:
        count += 1
        a[i], a[mini] = a[mini], a[i]
print(' '.join(map(str, a)))
print(count)

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 minj != i:
		k = a[i]
		a[i] = a[minj]
		a[minj] = k
		counter += 1
ans = list(map(str,a))
print(" ".join(ans))
print(counter)

Solution (Python):

number=eval(input())
swap=0
arr=list(map(int, input().split(' ')))
for i in range(number-1):
    minI=arr.index(min(arr[i:]),i)
    if i!=minI:
        arr[i],arr[minI]=arr[minI],arr[i]
        swap+=1
print(' '.join(map(str, arr)))
print(swap)

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

for k in range(n-1):
    print(str(A[k])+" ",end = "")
print(str(A[n-1]))
print(count)

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

print(*a)
print(ans)

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


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

    answer_list, answer_count = selectionSort(A, N)

    print(*answer_list)
    print(answer_count)

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

count = 0
for i in range(n):
    minj = i
    for j in range(i+1,n):
        if lst[j] < lst[minj]:
            minj = j
    if minj != i:
        lst[i], lst[minj] = lst[minj], lst[i]
        count += 1
print(*lst)
print(count)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(n):
    min_value = i
    for j in range(i,n):
        if l[min_value] > l[j]:
            min_value = j
    t = l[i]
    r = l[min_value]
    if l[i] > l[min_value]:
        l[i] = r
        l[min_value] = t
        count +=1
for s in range(n-1):
        print(l[s],end=' ')
print(l[-1])
print(count)

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

def selectionSort(a:list, n:int):
    count = 0
    for i in range(n):
        flag = 0
        minj = i
        for j in range(i, n):
            if a[j] < a[minj]:
                minj = j
                flag = 1
        if flag:
            a[i], a[minj] = a[minj], a[i]
            count += 1
    return a, count

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
	ptr = i
	for j in range(i + 1, N):
		if A[ptr] > A[j]:
			ptr = j
	if i != ptr:
		x = A[i]
		A[i] = A[ptr]
		A[ptr] = x
		ans += 1
s = str(A[0])
for i in range(1, N):
	s += " " + str(A[i])
print(s)
print(ans)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

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
    a = A[i]
    b = A[minj]
    A[i] = b
    A[minj] = a
    if minj != 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):
    min = i
    for j in range(i, N):
        if A[min] > A[j]:
            min = j
    A[i], A[min] = A[min], A[i]
    if min != i:
        count += 1


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

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

counter = 0
for i in range(n):
    minIdx = i
    for j in range(i,n):
        if A[j] < A[minIdx]:
            minIdx = j
    if minIdx != i:
        counter += 1
    A[i], A[minIdx] = A[minIdx], A[i]

for i in range(n):
    if i == n-1:
        print(A[i])
    else:
        print(A[i],end=' ')
print(counter)

Solution (Python):
def selection_sort(a, n):
    switch = 0
    for i in range(n):
        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
            switch += 1
    print(' '.join(map(str, a)))
    print(switch)


def main():
    n = int(input())
    nums = input()
    nums = list(map(int, nums.split(' ')))
    selection_sort(nums, n)


if __name__ == "__main__":
    main()

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

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

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

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

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

lst,change = selectionSort(lst)
print(" ".join(map(str,lst)))
print(change)

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

count = 0
for i in range(N):
    mini = min(S[i:N])
    for j in range(i,N):
        if S[j]==mini and i!=j and S[i]!=S[j]:
            S[i], S[j] = S[j], S[i]
            count += 1

for i in range(N):
    if i==N-1:
        print(S[i])
    else:
        print(S[i],end=' ')
print(count)

Solution (Python):
n = int(input())
L = list(map(int, input().split()))
cnt = 0
for i in range(len(L)-1):
    x = L[i+1:].index(min(L[i+1:])) + i + 1
    if L[i] > L[x]:
        L[i], L[x] = L[x], L[i]
        cnt += 1
print(' '.join(str(x) for x in L))
print(cnt)

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

    A[i],A[minj] = A[minj],A[i]

    if i != minj:
        cnt+=1
    

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

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

num_of_sorting = 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 is not minj:
    temp = A[i]
    A[i] = A[minj]
    A[minj] = temp
    num_of_sorting += 1
  
print(' '.join(map(str, A)))
print(f"{num_of_sorting}")

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

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

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


def selection_sort(A, n):
    count = 0
    for i in range(n-1):
        min_j = i
        for j in range(i+1, n):
            if A[min_j] > A[j]:
                min_j = j
        if min_j != i:
            A[i], A[min_j] = A[min_j], A[i]
            count += 1
    show(A, n)
    print(count)


def main():
    n = int(input())
    A = list(map(int, input().split()))
    selection_sort(A, n)


if __name__ == "__main__":
    main()

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

for i in range(N):
  min_j = i
  flag = False

  for j in range(i+1, N):
    if (A[min_j] > A[j]):
      min_j = j
      flag = True
  
  
  A[min_j], A[i] = A[i], A[min_j]

  if flag == True:
    count += 1

print(str(A).replace('[', '').replace(']', '').replace(',', ''))
print(count)

Solution (Python):
import sys

def print_data(data):
    last_index = len(data) - 1
    
    for idx, item in enumerate(data):
        print(item, end='')
        if idx != last_index:
            print(' ', end='')

    print('')
        
def main():
    N = int(input())
    data = list(map(int, input().split()))
    counter = 0
    
    for i in range(N):
        mini = i
        for j in range(i, N):
            if data[j] < data[mini]:
                mini = j
        if i == mini:
            pass
        else:
            hoge = data[mini]
            data[mini] = data[i]
            data[i] = hoge
            counter += 1
                  
        
    print_data(data)
    print(counter)
    
            
if __name__ == '__main__':
    main()

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

Solution (Python):
def SelectionSort(A):
    count_swap = 0
    for i in range(len(A)):
        mini = i
        for j in range(i,len(A)):
            if A[j] < A[mini]:
                mini = j
        if i != mini:
            count_swap += 1
        A[i],A[mini] = A[mini],A[i]
    
    return A,count_swap 
    

try:
    N = int(input())
    array = list(map(int,input().split()))
except ValueError:
    print('数値以外が入力されました')

result = SelectionSort(array)
print(*result[0])


print(result[1])

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

count = 0
for i in range(0,len(number)):
    mini = i
    for j in range(i,len(number)):
        if number[j] < number[mini]:
            mini = j
    if mini != i:
        count += 1
        temp = number[i]
        number[i] = number[mini]
        number[mini] = temp


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

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

N = int(input())
A = list(map(int, input().split()))
c = selectionSort(A, N)
for i in range(N):
    if i == N - 1:
        print(A[i])
    else:
        print(A[i], end=' ')
print(c)

Solution (Python):
from sys import stdin
N = int(input())
nums = list(map(lambda x: int(x), stdin.readline().split(' ')))
count = 0
for i in range(N-1):
    min = nums[i]
    min_id = i
    for j in range(i+1, N):
        if min > nums[j]:
            min = nums[j]
            min_id = j
    if i != min_id:
        nums[i], nums[min_id] = nums[min_id], nums[i]
        count += 1
output = ""
for i in nums:
    output += str(i) + ' '
print(output[:-1])
print(count)

Solution (Python):
length_list = int(input())
num_list = list(map(int, input().split()))

count = 0

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

Solution (Python):

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

Solution (Python):
def selection_sort(A, N):
  sw = 0
  for i in range(0,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:
      sw += 1
  print(*A)
  print(sw)

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

Solution (Python):
n = int(input())
t = list(map(int, input().split(' ')))
x = 0
for i in range(n):
    kome = i
    for j in range(i,n):
        if t[j] < t[kome]:
            kome = j
    if t[i] > t[kome]:
        t[i],t[kome] = t[kome],t[i]
        x = x + 1
t = [str(i) for i in t]
print(' '.join(t))
print(x)

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

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

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

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

Solution (Python):
input()
A = [int(x) for x in list(input().split())]
n = len(A)
counter = 0

for i in range(0, n-1, 1):
    minj = i
    for j in range(i, n, 1):
        if A[j] < A[minj]:
            minj = j
    if i == minj:
        continue
    tmp = A[i]
    A[i] = A[minj]
    A[minj] = tmp
    counter += 1

print(*A)
print(counter)

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:
        a = A[i]
        A[i] = A[minj]
        A[minj] = a
        count += 1
        
print(' '.join(map(str, A)))
print(count)

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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


if __name__ == '__main__':
    main()

Solution (Python):
def selectionSort(A):
    counter = 0
    for i, _ in enumerate(A):
        min_j = i
        for j in range(i, len(A)):
            if A[j] < A[min_j]:
                min_j = j
        A[i], A[min_j] = A[min_j], A[i]
        if i != min_j:
            counter += 1
    return A, counter
    
N = int(input())
A = list(map(int, input().split()))

ans = selectionSort(A)
print(' '.join(str(a) for a in ans[0]))
print(ans[1])

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

Solution (Python):
def selection_sort(array):
    counter = 0
    for i in range(len(array)):
        
        
        
        j_min = i
        for j in range(i, len(array)):
            
            if array[j] < array[j_min]:
                j_min = j
            
        
        
        if array[i] > array[j_min]:
            array[i], array[j_min] = array[j_min], array[i]
            
            counter += 1
            
    return array, counter

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


A_new, num_ans = selection_sort(A)

print(" ".join(map(str, A_new)))
print(num_ans)

Solution (Python):
def bubbleSort(A, N):
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1


def selectionSort(A, N):
    count =0
    for i in range(N):
        minidx = i
        for j in range(i,N):
            if A[j] < A[minidx]:
                minidx = j
        if minidx == i:
            continue
        A[i],A[minidx] = A[minidx],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):
n = int(input())

l = list(map(int, input().split()))
count = 0

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

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

Solution (Python):
import math

N = input()
A = map(int, raw_input().split())
c=0
for i in range(0,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 minj!=i:
    c+=1

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

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

counter = 0
for i in range(N-1):
    min_index = i
    for j in range(i,N):
        v = A[j]
        min = A[min_index]
        if A[j] < A[min_index]:
            min_index = j
    if min_index != i:
        temp = A[min_index]
        A[min_index] = A[i]
        A[i] = temp
        counter = counter + 1

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

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


def selection_sort(A):
    counter = 0
    for i in range(len(A)):
        _min = i
        for j in range(i, len(A)):
            if A[j] < A[_min]:
                _min = j
        A[i], A[_min] = A[_min], A[i]
        if i != _min:
            counter += 1
    print(" ".join([str(a) for a in A]))
    print(counter)
    return A


def main():
    _ = input()
    A = [int(i) for i in input().strip().split()]
    selection_sort(A)


if __name__ == "__main__":
    main()

Solution (Python):
n, *aa = map(int, open(0).read().split())

count = 0
for i in range(n):
    mini = i
    for j in range(i+1, n):
        if aa[j] < aa[mini]:
            mini = j
    if mini != i:
        aa[i], aa[mini] = aa[mini], aa[i]
        count += 1

print(*aa)
print(count)

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

count = 0
for idx1 in range(0, len(arr)):
    mins = idx1
    for idx2 in range(idx1, len(arr)):
        if arr[idx2] < arr[mins]:
            mins = idx2
    
    if mins != idx1:
        arr[idx1], arr[mins] = arr[mins], arr[idx1]
        count += 1

print(" ".join(map(str, arr)), count, sep="\n")

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
c = 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]
        c += 1
print(*A, sep=' ')
print(c)

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


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

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


while True:
    if len(A) == N:
        break
    else:
        print("Input again!")
        A = [int(x) for x in input().split()]


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

A,count = SelectionSort(A,N)
print(" ".join(map(str,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 i != minj:
        cnt += 1
    tmp = A[i]
    A[i] = A[minj]
    A[minj] = tmp
    
for k in range(n-1):
    print(A[k], end=' ')
print(A[n-1])
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:
    k=A[i]
    A[i]=A[minj]
    A[minj]=k
    cnt+=1
print(*A)
print(cnt)

Solution (Python):
def main():
    num = int(input())
    sort_nums = list(map(int, input().split()))
    
    min_num_index = 0
    temp_counter = 0
    for i in range(0, num):
        min_num_index = i
        for j in range(i, num):
            if sort_nums[j] < sort_nums[min_num_index]:
                min_num_index = j

        if not sort_nums[i] == sort_nums[min_num_index]:
            temp_counter += 1

            temp = sort_nums[i]
            sort_nums[i] = sort_nums[min_num_index]
            sort_nums[min_num_index] = temp
        
    print(" ".join([str(n) for n in sort_nums]))
    print(temp_counter)

if __name__ == '__main__':
    main()

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

cnt = 0
for i in range(n - 1):
    k = i
    for j in range(i + 1, n):
        if A[j] < A[k]:
            k = j

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

print(*A)
print(cnt)

Solution (Python):
def selection_sort(A, N):
    change_cnt = 0
    for i in range(0, N-1):
        min_idx = i
        for j in range(i+1, N):
            if A[j] < A[min_idx]:
                min_idx = j
        A[i], A[min_idx] = A[min_idx], A[i]
        if i != min_idx:
            change_cnt += 1
    print(" ".join([str(a) for a in A]))
    print(change_cnt)
N = int(input().rstrip())
A = [int(a) for a in input().rstrip().split(" ")]
selection_sort(A, N)

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

    print(*A)
    print(count)

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

selectionSort(A, N)

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
swapCnt = 0
for i in range(N):
    minNum = i
    for j in range(i, N):
        if A[j] < A[minNum]:
            minNum = j
    if minNum != i:
        A[minNum], A[i] = A[i], A[minNum]
        swapCnt += 1
print(' '.join(map(str, A)))
print(swapCnt)

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

a = 0
for i in range(len(A)-1):
  mini = i
  minv = A[i]
  for j in range(i, len(A)):
    if minv > A[j]:
      mini = j
      minv = A[j]
  if i != mini:
    A[i], A[mini] = A[mini], A[i]
    a += 1

print(" ".join(list(map(str, A))))
print(a)

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

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

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

selectionSort(a, n)

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

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

ans=str(num_list[0])
for i in range(1,len(num_list)):
    ans+=" "+str(num_list[i])
print(ans)
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 i != minj:
        A[i], A[minj] = A[minj], A[i]
        count += 1

print(*A)
print(count)

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

    for i in range(N):
        temp = i
        minj = A[i]
        for j in range(i+1,N):
            if A[j] < minj:
                minj = A[j]
                temp = j

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

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


main()

Solution (Python):
import sys

input = sys.stdin.readline


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

    ans = 0
    for i in range(N - 1):
        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]
            ans += 1

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


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 i != minj:
            cnt+=1
        A[i],A[minj]=A[minj],A[i]
    return(cnt)
a=int(input())
b=list(map(int,input().split(" ")))
c=selectionSort(b,a)
print(" ".join(list(map(str,b))),c,sep="\n")

Solution (Python):
from sys import stdin


def selection_sort(A, N):
    count = 0
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[minj] > A[j]:
                minj = j
        
        if A[minj] != A[i]:
            count += 1
            A[minj], A[i] = A[i], A[minj]
        
    return count
                
def main():
    read = stdin.readline
    N = int(read())
    data = list(map(int, read().split(' ')))
    count = selection_sort(data, N)
    for i in range(N-1):
        print(data[i], end=' ')
    print(data[N-1])
    print(count)

if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
ans=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: continue
  tmp=A[i]
  A[i]=A[minj]
  A[minj]=tmp
  ans+=1
print(*A)
print(ans)

Solution (Python):


def selectionSort(A, n):
    res = 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]        
            res += 1
        
    return A, res

n = int(input())
l = list(map(int, input().split()))
res_l, res = selectionSort(l, n)
print(*res_l)
print(res)

Solution (Python):
def selectionSort(table):
    swap_count = 0
    for nAchieve in range(len(table)):
        min_index = nAchieve
        for i in range(nAchieve, len(table)):
            if table[i] < table[min_index]:
                min_index = i
        if min_index != nAchieve:
            table[min_index], table[nAchieve] = table[nAchieve], table[min_index]
            swap_count += 1
    return swap_count


element = int(input())
table = list(map(int, input().split()))
swap_count = selectionSort(table)

print(' '.join(map(str, table)))
print(swap_count)

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 minj != i:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            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())
x = list(map(int,input().split()))
c = 0

for i in range(n):
    min = i
    for j in range(i+1,n):
        if x[min] > x[j]:
            min = j
    if i != min:       
        x[i],x[min] = x[min],x[i]
        c += 1

print(*x)
print(c)

Solution (Python):

from sys import stdin

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

n = int(stdin.readline().rstrip())
A = list(map(int, stdin.readline().split()))
ans = selection_sort(A, n)
print(' '.join(map(str,ans[0])))
print(ans[1])

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

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

Solution (Python):
from sys import stdin
N = int(input())
A = [int(x) for x in stdin.readline().split(' ')]

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

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