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())
ns=list(map(int,input().split()))
ans=0
for i in range(n):
    minj=i
    for j in range(i,n):
        if(ns[j]<ns[minj]):
            minj=j
    if i!=minj:
        ans+=1
        k=ns[i]
        ns[i]=ns[minj]
        ns[minj]=k

for i in range(n):
    if(i!=n-1):
        print(ns[i],end=' ')
print(ns[n-1])
print(ans)

Solution (Python):



''' ??????????????? '''





def selection_sort(A, N):
    swap_num = 0  

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

    return (A, swap_num)


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

Solution (Python):



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


if __name__ == '__main__':
    n = int(input())
    a = [int(n) for n in input().split()]
    ans, cnt = selection_sort(n, a)
    print(' '.join(map(str, ans)))
    print(cnt)

Solution (Python):
def selection_sort(seq):
    l = len(seq)
    cnt = 0
    for i in range(l):
        mi = i
        for j in range(i+1, l):
            if seq[j] < seq[mi]:
                mi = j
        if i is not mi:
            seq[i], seq[mi] = seq[mi], seq[i]
            cnt += 1
    return seq, cnt

n = int(input())
a = list(map(int, input().split()))
sorted_a, num_swap = selection_sort(a)
print(' '.join(map(str, sorted_a)))
print(num_swap)

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

for i in range(N):
  mini = i

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

  if i != mini:
    A[i], A[mini] = A[mini], A[i]
    num_of_swp += 1

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

Solution (Python):


def selection_sort(num_list):
    num_swap = 0
    for i in range(len(num_list)):
        mini = i
        for j in range(i, len(num_list)):
            if num_list[j] < num_list[mini]:
                mini = j
        if i != mini:
            num_list[i], num_list[mini] = num_list[mini], num_list[i]
            num_swap = num_swap + 1
    return num_swap, num_list

def show_list(list):
    i = 0;
    while(i < len(list)-1):
        print(list[i], end=" ")
        i = i + 1
    print(list[i])

num = int(input())
num_list = [int(x) for i, x in enumerate(input().split()) if i < num]
num_swap, num_list = selection_sort(num_list)
show_list(num_list)
print(num_swap)

Solution (Python):

num_length = int(input())
num_array = [int(x) for x in input().split()]


def selectionsort(A, N):
    exchange_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:
            A[i], A[minj] = A[minj], A[i]
            exchange_counter += 1

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

selectionsort(num_array, num_length)

Solution (Python):
def select_sort(array):
    N = len(array)
    count = 0
    
    for i in range(N - 1):
        min_i = i + array[i:].index(min(array[i:]))
        if i != min_i:
            count += 1
        array[i], array[min_i] = array[min_i], array[i]
        
    return array, count

n = int(input())
array = [int(i) for i in input().split()]
result = select_sort(array)

print(*result[0])
print(result[1])

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

Solution (Python):
def serect_sort(r, n):
    cnt = 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:
            cnt +=1
    print(*r)
    print(cnt)

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

Solution (Python):


n = int(input())
str = input()
str = str.split()
a = []
for i in range(n):
    a.append(int(str[i]))

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

    tmp = a[min]
    a[min] = a[i]
    a[i] = tmp
    if a[min] != a[i]:
        count += 1
for i in range(n-1):
    print(a[i],end = ' ')
print(a[n-1])
print(count)

Solution (Python):

def SelectionSort(A, N):
    swap_n = 0

    for i in range(N):
        min_j = i

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

        if i != min_j:
            A[i], A[min_j] = A[min_j], A[i]
            swap_n += 1

    return swap_n

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

swap_n = SelectionSort(A, N)

print(*A)
print(swap_n)

Solution (Python):
def selectionSort(A, N):
    swap_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]
            swap_count += 1
    return swap_count

n = int(input())
A = list(map(int, input().split()))
count = selectionSort(A, n)
print(*A)
print(count)

Solution (Python):
def selectionSort(A, N):
    swap_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]
            swap_count += 1
    return swap_count

n = int(input())
A = list(map(int, input().split()))
count = selectionSort(A, n)
print(*A)
print(count)

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

ans, cnt = selection_sort(int(input()), [int(s) for s in input().split()])
print(' '.join(str(s) for s in ans), cnt, sep='\n')

Solution (Python):



def selection_sort(seq, l):
    cnt = 0

    for head_i in range(l):
        flag = False

        min_i = head_i
        for target_i in range(head_i+1, l):
            if seq[target_i] < seq[min_i]:
                min_i = target_i
                flag = True
        if flag:
            seq[head_i], seq[min_i] = seq[min_i], seq[head_i]
            cnt += 1

    print(' '.join([str(n) for n in seq]))
    print(cnt)


def to_int(v):
    return int(v)


def to_seq(v):
    return [int(c) for c in v.split()]


if __name__ == '__main__':
    l = to_int(input())
    seq = to_seq(input())

    selection_sort(seq, l)

Solution (Python):
def selection(A,n):
  count = 0
  for i in range(0,n-1):
    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
  printList(A)
  print(count)

def printList(A):
  print(" ".join(str(x) for x in A))

n = int(input())
A = [int(x) for x in input().split()]
selection(A,n)

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

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


if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()

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

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

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

count = selectionSort(A, N)

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

Solution (Python):
def selectionSort():
    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
        
        A[i], A[minj] = A[minj], A[i]
        if not(minj == i):
            C += 1
    
    print(*A)
    print(C)
    
selectionSort()

Solution (Python):
n = int(input())
arrey = [int(i) for i in input().split()]
count = 0

for i in range(len(arrey)):
    minj = i
    change = False
    for j in range(i+1, len(arrey)):
        if arrey[minj] > arrey[j]:
            minj = j
            change = True
    if change:
        arrey[i], arrey[minj] = arrey[minj], arrey[i]
        count += 1

for i in range(len(arrey)):
    print(str(arrey[i])+' ',end='') if i != len(arrey)-1 else print(arrey[i])
print(count)

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

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

Solution (Python):
def selectionSort(a):
    count = 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:
            ret = a[i]
            a[i] = a[mini]
            a[mini] = ret
            count += 1
    print(" ".join(map(str,a)))
    print(count)
n = int(input())
a = list(map(int,input().split()))
selectionSort(a)

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

counter=0
for i in range(N):
	Ar = A[i:] 
	num = Ar.index(min(Ar)) 
	if num != 0:
		A[i], A[(i+num)] = A[(i+num)], A[i]
		counter += 1
print(" ".join(map(str,A)))
print(counter)

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

A = [int(x) for x in input().split()]
num_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):
        A[i], A[minj] = A[minj], A[i]
        num_c += 1

print((" ").join(str(x) for x in A))
print(num_c)

Solution (Python):
def selectionSort(n, A):
    cnt =0
    for i in range(n):
        minj = i
        for j in range(i,n):
            if A[minj] > A[j]:
                minj = j
        if i != minj:
            A[i],A[minj] = A[minj],A[i]
            cnt += 1
    print(*A)
    print(cnt)

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

Solution (Python):
def selection_Sort(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
    return (count)

if __name__ == '__main__':
    n = int(input())
    data = [int(i) for i in input().split()]
    result = selection_Sort(data,n)
    print(" ".join(map(str,data)))
    print(result)

Solution (Python):
N = int(input())
a = [int(i) for i 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 i != minj:
        count += 1
        a[i], a[minj] = a[minj], a[i]
print(" ".join(map(str, a)))
print(count)

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

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

print(' '.join(list(map(str, line))))
print(cnt)

Solution (Python):
data_num = int(input())
nums = list(map(int, input().split(" ")))
cnt = 0
for i in range(data_num):
    min_idx = i
    for j in range(i, data_num):
        if nums[j] < nums[min_idx]:
            min_idx = j

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

print(" ".join(map(str,nums)) + "\n" + str(cnt))

Solution (Python):
def pretty_sequence(sequence):
    n = len(sequence)
    for i in range(n-1):
        print(format(sequence[i]) + ' ', end='')
    print(sequence[n - 1])

n = int(input())
sequence = [int(x) for x in input().split(' ')]


def selectionsort(seq, x):
    count = 0
    for i in range(x):
        minj = i
        for j in range(i, x):
            if seq[j] < seq[minj]:
                minj = j
        if seq[i] != seq[minj]:
            tmp_val = seq[i]
            seq[i] = seq[minj]
            seq[minj] = tmp_val
            count += 1
    return seq, count

sequence, count = selectionsort(sequence, n)
pretty_sequence(sequence)
print(count)

Solution (Python):
N = int(input())
A = [int(x) for x in 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 i != minj:
        times += 1
    A[i], A[minj] = A[minj], A[i]
  


print(*A)
print(times)

Solution (Python):
def selectionSort():
    l = int(input())
    A = list(map(int, input().split(" ")))
    count = 0
    for i in range(l-1):
        mini = i
        for j in range(i, l-1):
            if (A[mini]>A[j+1]):
                mini = j+1
        if (i != mini):
            temp = A[mini]
            A[mini] = A[i]
            A[i] = temp
            count += 1
    print(" ".join(map(str, A)))
    print(count)
selectionSort()

Solution (Python):


S = int(input())
N = list(map(int,input().split(" ")))


def seleSort(n,s):
    c =0
    for i in range(s):
        minj = i
        for j in range(i+1,s):
            if n[j]<n[minj]:
                minj = j
                
        n[i],n[minj]=n[minj],n[i]
        if i!= minj:
            c+=1
    print(" ".join(list(map(str,n))))
    print(c)
        
        
seleSort(N,S)

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

swap_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]
        swap_count += 1
print(*A)
print(swap_count)

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

for i in range(n):
    mi = min(a[i:])
    if a[i] > mi:
        j = a[i:].index(mi)+i
        a[i], a[j] = a[j], a[i]
        cnt += 1

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

Solution (Python):
N, A, cou   = int(input()), [int(temp) for temp in input().split()], 0

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

Solution (Python):


import sys
import os
import math


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


def selection_sort(A):
    swap_num = 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:
            A[i], A[min_i] = A[min_i], A[i]
            swap_num += 1
    print(*A)
    print(swap_num)

selection_sort(A)

Solution (Python):



def selectionSort(line, size):
    """Rerutn sorted list.

    >>> selectionSort([1, 2, 3, 4], 4)
    ([1, 2, 3, 4], 0)

    >>> selectionSort([5,6,4,2,1,3], 6)
    ([1, 2, 3, 4, 5, 6], 4)
    """
    count = 0
    for i in range(0, size):
        minj = i
        for j in range(i, size):
            if line[j] < line[minj]:
                minj = j
        if line[i] != line[minj]:
            tmp = line[i]
            line[i] = line[minj]
            line[minj] = tmp
            count += 1
    return line, count


def main():
    size = int(input())
    line = list(map(int, input().split()))
    ans_list, count = selectionSort(line, size)
    ans = " ".join(map(str, ans_list))
    print(ans)
    print(count)


if __name__ == '__main__':
    import doctest
    doctest.testmod()
    main()

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

x = 0

for i in range(N):
    minj = i
    y = 0
    for j in range(i,N):
        if A[j] < A[minj]:
            minj = j
            y = 1
            
    v = A[i]
    A[i] = A[minj]
    A[minj] = v
    x += y
    
for i in range(N-1):
    print A[i],
print A[-1]

print x

Solution (Python):
N = input()
A = map(int,raw_input().split())
x = 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:        
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
        x += 1
    
for i in range(N-1):
    print A[i],
print A[-1]
print x

Solution (Python):


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

swapCount = 0
for i in range(0, N):
    minIndex = i
    for j in range(i, N):
        if a[j] < a[minIndex]:
            minIndex = j
    
    if i != minIndex:
        tmp = a[i]
        a[i] = a[minIndex]
        a[minIndex] = tmp
        swapCount += 1

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

Solution (Python):
def selection_sort(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

    return (a,count)

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

Solution (Python):
def selectionSort(a,n):
    cnt = 0
    for i in range(n-1):
        minj = i
        for j in range(i+1,n):
            if a[j] < a[minj]:
                minj = j

        if i != minj: 
            temp = a[minj]
            a[minj] = a[i]
            a[i] = temp
            cnt += 1
    print(" ".join(map(str,a)))
    print(cnt)

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

selectionSort(a,n)

Solution (Python):
def main():
    tmp = input()
    ls = list(map(int, input().split(' ')))
    count = 0
    
    for i in range(len(ls)):
        minj = i
        
        for j in range(i, len(ls)):
            if ls[j] < ls[minj]:
                minj = j
        ls[i], ls[minj] = ls[minj], ls[i]

        if minj != i:
            count += 1

    print(' '.join(map(str,ls)))
    print(count)
    
if __name__ == '__main__':
    main()

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

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

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

	selection_sort(A, n)

Solution (Python):

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

N=int(input())
A=input().split()
c=selectionSort(A,N)
S=""
for i in range(N-1):
    S+=A[i]+" "
S+=str(A[-1])
print(S)
print(c)

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

def selectSort(A, N):
 sw = 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]
   sw += 1
 return str(sw)

sw = selectSort(A, N)
print(" ".join(map(str, A)))
print(sw)

Solution (Python):
p = int(input())
y = list(map(int, input().split()))
t = 0
for h in range(p):
    o = h
    for n in range(h, p):
        if y[n] < y[o]: o = n
    if h != o:
        y[h], y[o] = y[o], y[h]
        t += 1
print(*y)
print(t)

Solution (Python):


def print_list(X):
    first_flag = True
    for val in X:
        if first_flag:
            print_line = str(val)
            first_flag = False
        else:
            print_line = print_line + ' ' + str(val)
    print(print_line)

def selection_sort(A, N):
    counter = 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]
            counter += 1

    print_list(A)
    print(counter)

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

selection_sort(A, N)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
cnt = 0
chge = 0
for i in range(N):
    mn = A[i]
    for j in range(i+1, N):
        if mn > A[j]:
            mn = A[j]
            idx = j
            chge = 1
    if chge:
        A[idx] = A[i]
        A[i] = mn
        cnt += 1
        chge = 0

for i in range(N):
    if i == N - 1:
        print(A[i])
    else:
        print(str(A[i]), end = " ")
print(cnt)

Solution (Python):
N = int(raw_input())
lst = map(int, raw_input().split())
cnt = 0
for i in range(0, len(lst)):
    m = i
    for j in range(i, len(lst)):
        if lst[m] > lst[j]:
            m = j
    if m != i:
        lst[i], lst[m] = lst[m], lst[i]
        cnt+=1

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

Solution (Python):
raw_input()
lst=map(int, raw_input().split())

cnt = 0
for i in range(0, len(lst)):
    m = i
    for j in range(i, len(lst)):
        if lst[m] > lst[j]:
            m = j
    if m != i:
        lst[i], lst[m] = lst[m], lst[i]
        cnt+=1

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

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

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

    A, count = selectionSort(A, N)

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

def selectionSort(A, N):
    count = 0

    for i in range(0, 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]
            count += 1

    return A, count

if __name__ == '__main__':
    main()

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

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

Solution (Python):

"""
Created on Sun Jun 18 09:48:56 2017

@author: syaga
"""

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    num = 0
    for i in range(0, 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 minj != i:
            num += 1
    print(" ".join(map(str, A)))
    print(num)

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

c = 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:
        tmp = a[i]
        a[i] = a[minj]
        a[minj] = tmp
        c += 1

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

Solution (Python):
def selectSort(A, N):
      cnt = 0
      for i in range(0,N):
            mina = A[i]
            k = 0
            for j in range(i+1,N):
                  if int(mina) > int(A[j]):
                        mina = A[j]
                        k = j
            if int(A[i]) > int(mina):
                  swap = A[i]
                  A[i] = mina
                  A[k] = swap
                  cnt = cnt + 1
      for t in range(0,N):
            if t < N-1:
                  print(A[t], end=" ")
            else:
                  print(A[t])
      print(cnt)
            

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

Solution (Python):
N = int(input())
A = [int(A) for A in input().split()]
cnt = 0
for i in range(N):
    A_min = i
    for j in range(i, N):
        if A[A_min] > A[j]:
            A_min = j
    if i != A_min:
        t = A[i]
        A[i] = A[A_min]
        A[A_min] = t
        cnt += 1

for i in range(N):
    if i == N - 1:
        print(A[i])
    else:
        print("{}".format(A[i]), end=' ')

print(cnt)

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


def main():
    N = int(input().rstrip())
    A = list(map(int, input().rstrip().split()))
    
    sw = selection_sort(A, N)
    
    print(' '.join(map(str, A)))
    print(sw)
    
    
if __name__ == '__main__':
    main()

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

def SelectionSort(N, A):
    cnt = 0
    for i in range(N):
        min_i = i
        for j in range(i, N):
            if A[j] < A[min_i]:
                min_i = j
        if i != min_i:
            A[i], A[min_i] = A[min_i], A[i]
            cnt += 1
    return A, cnt
    
res = SelectionSort(N, A)
print(" ".join(map(str, res[0])))
print(res[1])

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 A, count



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

    A, count = selection(A, N)
    print (*A)
    print (count)

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

def print_list(A):
    for a in A[:-1]:
        print ("%d "%a, end="")
    print(A[-1])

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
    return A, count
        
A_sorted, c = SelectionSort(A, N)

print_list(A_sorted)
print(c)

Solution (Python):
import sys

def swap(a, i, j):
    tmp = a[j]
    a[j] = a[i]
    a[i] = tmp

def list_to_string(a):
    s = ""
    for n in a:
        s += str(n) + " "
    return s.strip()

num = int(sys.stdin.readline().strip())

array = map(lambda x: int(x), sys.stdin.readline().strip().split(" "))

swap_num = 0

for start_index in range(0, len(array)):
    min_index = start_index
    for index in range(start_index, len(array)):
        if array[min_index] > array[index]:
            min_index = index
    if min_index != start_index:
        swap(array, min_index, start_index)
        swap_num += 1
        

print list_to_string(array)
print str(swap_num)

Solution (Python):


"""
???????????????
?????????????????????????¨??????????????????§?????????????°????????????????????????????????????´???????????¢?????´???????????§??????

1 selectionSort(A, N) // N??????????´??????????0-?????????????????????A
2   for i ??? 0 ?????? N-1 ?????§
3     minj = i
4     for j ??? i ?????? N-1 ?????§
5       if A[j] < A[minj]
6         minj = j
7     A[i] ??¨ A[minj] ?????????

"""
import math

def swap(A, i, j):
    x = A[i]
    A[i] = A[j]
    A[j] = x

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


N = int(input().strip())
A = list(map(int,input().strip().split()))
cnt = sSort(A,N)
print(" ".join(map(str,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 is not minj:
        A[i], A[minj] = A[minj], A[i]
        cnt += 1

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

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

    a = list(A)
    ans, n = selectionSort(a, N)
    print(*ans, sep=' ')
    print(n)

def selectionSort(a, n):
    k = 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 a[i] != a[minj]:
            k += 1
    return a, k

main()

Solution (Python):
n = int(input())
data = [int(s) for s in input().split()]

change = 0
new = []
for idx in range(n):
	idx_min = data[idx:].index(min(data[idx:])) + idx
	if idx_min > idx:
		data[idx],data[idx_min] = data[idx_min],data[idx]
		change += 1

print(' '.join([str(d) for d in data]))
print(change)

Solution (Python):
def selectionSort(nums,n):
    k=0
    for i in range(n):
        minj=i
        for j in range(i,n):
            if nums[j]<nums[minj]:
                minj=j
        if nums[i]!=nums[minj]:
            nums[i],nums[minj]=nums[minj],nums[i]
            
            k+=1
    return nums,k
    
n=int(input())
nums=list(map(int,input().split()))

nums,k=selectionSort(nums,n)
print(*nums)
print(k)