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())
l=list(map(int,input().split()))

counter=0
for i in range(n):
    minimum=i
    for j in range(i,n):
        if l[minimum]>l[j]:
            minimum=j
    if i!=minimum:
        l[minimum],l[i]=l[i],l[minimum]
        counter+=1
print(*l)
print(counter)

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

for i in range(n):
    minj = i
    for j in range(i,n):
        if k[j] < k[minj]:
            minj = j
    x = k[i]
    k[i] = k[minj]
    k[minj]=x
    if k[i] != k[minj]:
        m += 1


print(' '.join(map(str, k)))
print(m)

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

Solution (Python):
n = int(raw_input())
a = map(int, raw_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 a[i] != a[minj]:
        tmp = a[i]
        a[i] = a[minj]
        a[minj] = tmp
        count += 1

for i in range(n):
    if i == n-1:
        print a[i]
    else:
        print a[i],

print count

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

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

Solution (Python):
N=int(input())
A=[int(i) for i in 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 i!=minj:
        t=A[i]
        A[i]=A[minj]
        A[minj]=t
        C+=1
 
for i in range(N):
    A[i]=str(A[i])
print(" ".join(A))
print(C)

Solution (Python):


import sys, math, os


PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def printA(A):
    print(' '.join([str(a) for a in A]))

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

        
N = int(input())
A = [int(_) for _ in input().split()]
A, swaps = selection_sort(A)
printA(A)
print(swaps)

Solution (Python):
dummy = input()

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



count = 0
if len(s_list) == 1:
    for i,row in enumerate(s_list):
        if i == 0:
            print(row,end='')
        else:
            print('',row,end='')
    print()
    print(count)

else:
    for i in range(len(s_list)-1):

        min_i = i

        for j in range(i,len(s_list)):

            if s_list[j] < s_list[min_i]:
                min_i = j

        if s_list[i] != s_list[min_i]:
            count += 1
            min_num = s_list[min_i]

            s_list[min_i] = s_list[i]
            s_list[i]     = min_num

    for i,row in enumerate(s_list):
        if i == 0:
            print(row,end='')
        else:
            print('',row,end='')
    print()
    print(count)

Solution (Python):
def sort(a):
    n = len(a)
    nswaps = 0
    for i in range(n):
        minv = None
        minp = -1
        for j in range(i, n):
            if minv == None or minv > a[j]:
                minv = a[j]
                minp = j
        a[minp], a[i] = a[i], a[minp]
        if i != minp:
            nswaps += 1
    return nswaps

n = int(raw_input())
a = map(int, raw_input().split(' '))
nswaps = sort(a)
print ' '.join(map(str, a))
print nswaps

Solution (Python):
N = int(input())
A = [int(n) for n in input().split()]
cnt = 0
for i in range(N):
    min_x = A[i]
    exchange = "no"
    for j in range(i+1, N):
        if min_x > A[j]:
            min_x = A[j]
            index = j
            exchange = "ok"
    if exchange == "ok":
        A[index] = A[i]
        A[i] = min_x
        cnt += 1
for i in range(N):
    if i == N - 1:
        print(A[i])
    else:
        print(A[i], end=" ")
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 A[minj] != A[i]:
        cnt += 1
    
    buf = A[minj]
    A[minj] = A[i]
    A[i] = buf


print(' '.join(str(x) for x in A))
print(cnt)

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

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


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

selectionSort(L, N)

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

count = 0

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

print( *a )
print( count )

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
swap = 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:
        swap += 1
print(" ".join(list(map(str, A))))
print(swap)

Solution (Python):

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

swapOperation = 0

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

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

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

Solution (Python):

def selsort(array):
    counter = 0
    for i in range(len(array)):
        minnum = i
        for c in range(i,len(array)):
            if array[c] < array[minnum]:
                minnum = c
        if minnum != i:
            x = array[i]
            array[i] = array[minnum]
            array[minnum] = x
            counter = counter + 1
    array.append(counter)

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

selsort(arr)
print(' '.join([str(i) for i in arr[:-1]]))
print(arr[-1])

Solution (Python):
def selections(N):
    count = 0
    for i in range(len(N)):
        mini = i
        for j in range(i+1, len(N)):
            if N[mini] > N[j]:
                mini = j
        if i != mini:
            N[mini], N[i] = N[i], N[mini]
            count += 1
    c = 1
    for i in N:
        print(i, end='')
        if c < len(N):
            print(' ', end='')
            c += 1
    print('')
    print(count)
    
n = int(input())
numbers = list(map(int, input().split()))

selections(numbers)

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

Solution (Python):
def selectionSort(numbers):
    n = len(numbers)
    count = 0
    for i in range(n):
        min_j = i
        for j in range(i + 1, n):
            if numbers[j] < numbers[min_j]:
                min_j = j
        if min_j != i:
            temp = numbers[i]
            numbers[i] = numbers[min_j]
            numbers[min_j] = temp
            count += 1
    return (" ".join(list(map(str, numbers))), count)


def inputInline():
    int(input())
    numbers = list(map(int, input().split(" ")))
    return numbers


result = selectionSort(inputInline())
print(result[0])
print(result[1])

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

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

	c = selectionsort(data, n)
	print(*data)
	print(c)

if __name__ == "__main__":
	main()

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


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())
a = list(map(int,input().split()))

mini = 0
count = 0

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

for i in range(n):
    if i != n-1:
        print(a[i],end=" ")
    else:
        print(a[i])
print(count)

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


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

Solution (Python):
def selection_sort(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
    print " ".join(map(str, A))
    print c


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

selection_sort(A, n)

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

        if i != minj:
            tmp = lst[i]
            lst[i] = lst[minj]
            lst[minj] = tmp
            cnt += 1
    return (lst, cnt)


if __name__ == "__main__":
    n = int(input())
    lst = [int(n) for n in input().split()]
    result, cnt = selectionSort(lst, n)
    print(" ".join(str(n) for n in result))
    print(cnt)

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

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

A, counter = selectionSort(A, N)
print " ".join(map(str, A))
print counter

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):
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
    print(" ".join(map(str, A)))
    print(count)


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

SelectionSort(A)

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

N = int(input())
A = list(map(int,input().split()))
X , cnt = selectionSort(A,N)
print(*X)
print(cnt)

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

temp = 0
cnt = 0
for i in range(n):
	flag = 0
	min = i
	for j in range(i+1,n):
		if a[min] > a[j]:
			min = j
			flag = 1
	temp = a[i]
	a[i] = a[min]
	a[min] = temp
	cnt += flag

for i in range(n):
	if i != n-1:
		print(a[i]),
	else:
		print(a[i])

print cnt

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

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

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

    return A,count

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

A,count = selectionSort(A,N)

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

print(count)

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

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

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

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

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

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

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

count = 0

for i in range(n - 1):
    minx = i
    for j in range(i + 1,n):
        if x[j] < x[minx]:
            minx = j
        
    if not i == minx:
        x[i],x[minx]=x[minx],x[i]
        count += 1

x = list(map(str,x))
print (" ".join(x))
print(count)

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

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

sortedA, nSwap = selectionSort(A)
print(' '.join(map(str, sortedA)))
print(nSwap)

Solution (Python):
def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]
    exchange_count = 0


    for i in range(n) :
        minj = i
        for j in range(i, n) :
            if nums[j] < nums[minj] :
                minj = j
        if minj != i :
            exchange_count += 1
        nums[i], nums[minj] = nums[minj], nums[i]

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

if __name__ == '__main__' :
    main()

Solution (Python):
def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]
    exchange_count = 0

    for i in range(n) :
        minj = i
        for j in range(i, n) :
            if nums[j] < nums[minj] :
                minj = j
        if minj != i :
                exchange_count += 1
        nums[i], nums[minj] = nums[minj], nums[i]

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

if __name__ == '__main__' :
    main()

Solution (Python):
def main() :
    n = int(input())
    nums = [int(i) for i in input().split()]
    exchange_count = 0

    for i in range(n) :
        min_idx = nums[i:].index(min(nums[i:]))
        if nums[i] != nums[min_idx + i] :
            exchange_count += 1
        nums[i], nums[min_idx + i] = nums[min_idx + i], nums[i]

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

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

print(*a)
print(c)

Solution (Python):
def selectionSort(A, N):
    s = 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:
            s += 1
    t = str(A[0])
    for i in range(1,N):
        t = t + " " + str(A[i])
    print(t)
    print(s)

n = int(input())
a = [int(i) for i in input().split()]

selectionSort(a, n)

Solution (Python):
def selectionSort(A, N):
    s = 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:
            s += 1
    t = str(A[0])
    for i in range(1,N):
        t = t + " " + str(A[i])
    print(t)
    print(s)

n = int(input())
a = [int(i) for i in input().split()]

selectionSort(a, n)

Solution (Python):
NN=raw_input()
N=raw_input()
A = [int(i) for i in N.split()]
swap=0

for i in range(int(NN)):
  mini = i
  for j in range(i,int(NN)):
    if A[j] < A[mini]:
      mini = j
  if i != mini:
    t = A[i]
    A[i] = A[mini]
    A[mini] = t
    swap+=1
      
print ' '.join([str(k) for k in A])
print swap

Solution (Python):
n = int(input())
line = input()
arr= line.split(" ")
nums = []
for c in range(n):
    nums.append(int(arr[c]))

convert_n = 0
for i in range(len(nums)):
    minj = i
    for j in range(i, len(nums)):
        if nums[j] < nums[minj]:
            minj = j
    tmp = nums[i]
    nums[i] = nums[minj]
    nums[minj] = tmp
    if i != minj:
        convert_n += 1

n_list_str = ""
for num in nums:
    n_list_str += str(num)
    n_list_str += " "
print(n_list_str.rstrip(" "))
print(convert_n)

Solution (Python):
import sys

ERROR_INPUT = 'input is invalid'


def main():
    n = get_length()
    arr = get_array(length=n)

    sourtLi, count = selectionSort(li=arr, length=n)
    print(*sourtLi)
    print(count)
    return 0


def get_length():
    n = int(input())
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n


def get_array(length):
    nums = input().split(' ')
    return [str2int(string=n) for n in nums]


def str2int(string):
    n = int(string)
    if n < 0 or n > 100:
        print(ERROR_INPUT)
        sys.exit(1)
    else:
        return n


def selectionSort(li, length):
    count = 0

    for i in range(0, length - 1):
        min_index = i
        for j in range(i, length):
            if li[j] < li[min_index]:
                min_index = j

        if i != min_index:
            li[i], li[min_index] = li[min_index], li[i]
            count += 1

    return li, count


main()

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

input()
input=input()
A=[int(s) for s in input.split(' ')]
t=selectsort(A)
print (' '.join(map(str,A)))
print(t)

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

def selectionSort(a, n):
    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:
            a[i],a[mini] = a[mini],a[i]
            count += 1
    print(*a)
    print(count)

selectionSort(a,n)

Solution (Python):


import sys
import math

class Algo:
  @staticmethod
  def insertionSort(r, n):
    count = 0
    for i in range(0,n):
      minj = i
      for j in range(i,n):
        if r[j] < r[minj]:
          minj = j
      if r[i] != r[minj]:
        r[i], r[minj] = r[minj], r[i]
        count += 1
    
    for i in range(0,n):
      if i == n-1:
        print(r[i])
      else:
        print(r[i], " ", sep="", end="")
    print(count)

N = int(input())
R= list(map(int, input().split()))
Algo.insertionSort(R, N)

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split(' ')))
sw=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:
        sw=sw+1
print(" ".join(map(str,a)))
print(str(sw))

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

    print(*A)
    print(count)

arr_length = int(input())
arr_num = [int(i) for i in input().split(" ")]

selectionSort(arr_num, arr_length)

Solution (Python):
def selection_sort(A):
    n = len(A)
    swap_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:
            A[i], A[mini] = A[mini], A[i]
            swap_cnt += 1
    return A, swap_cnt

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

Solution (Python):
import sys

def selection_sort(x):
    count = 0
    for i in range(0,len(l)-1):
        mini = i
        for j in range(i+1,len(l)):
            if(x[j] < x[mini]):
                mini = j
        if(mini != i):
            count += 1
            temp = x[i]
            x[i] = x[mini]
            x[mini] = temp
    for data in x:
        print data,
    print
    print count


l = []
for input in sys.stdin:
    l.append(input)
l = l[1:]
l = l[0].split()
for i in range(0,len(l)):
    l[i] = int(l[i])
selection_sort(l)

Solution (Python):
def selection(l):
	N = len(l)
	count = 0

	for i in range(N):
		minj = i

		for j in range(i, N):
			if l[j] < l[minj]:
				minj = j
		if i == minj:
			continue
		else:
			l[i], l[minj] = l[minj], l[i]
			count += 1

	return l, count




if __name__ == '__main__':
	n = int(input())
	l = input().split()

	for i in range(n):
		l[i] = int(l[i])

	l, c = selection(l)
	count = 0
	leng = len(l)
	for i in l:
		count += 1
		if count < leng:
			print(i, end =' ')
		else:
			print(i)
			print(c)

Solution (Python):
def sel_sort(A, N):
    ''' 選択ソート '''
    count = 0
    for n in range(N):
        minm = n
        for m in range(n, N):
            if A[m] < A[minm]:
                minm = m
            
        if minm != n:
            A[n], A[minm] = A[minm], A[n]
            count += 1
    
    return (A, count)


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

    ans = sel_sort(A, N)

    print(' '.join([str(x) for x in ans[0]]))
    print(ans[1])

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

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

A, sw = selectionSort(A)

print(*A)
print(sw)

Solution (Python):
n=int(input())
s=input().split(' ')
m=0

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

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:
            count += 1

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

    return A, count

if __name__ == '__main__':

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

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

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

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

print(*arr)
print(count)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
c=0
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):
count = int(input());
data = [int(n) for n in input().split(" ")];

def selection_sort(data):
    count = len(data);
    o = 0;
    for i in range(count):
        minI = i;
        for j in range(i + 1, count):
            if data[j] < data[minI]:
                minI = j;
        if minI != i:
            temp = data[i];
            data[i] = data[minI];
            data[minI] = temp;
            o += 1;
    show(data);
    print(o);

def show(data):
    print(" ".join(str(n) for n in data));

selection_sort(data);

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

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

selectionSort(A,N)

Solution (Python):

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

Solution (Python):
n, data = int(input()), list(map(int, input().split()))
idx, t = 0, 0
for i in range(n-1):
    for j in range(i, n):
        if j == i:
            idx = j
        elif data[idx] > data[j]:
            idx = j
    if data[i] > data[idx]:
        data[i], data[idx] = data[idx], data[i]
        t += 1
print(" ".join(map(str, data)))
print(t)

Solution (Python):
n, data = int(input()), list(map(int, input().split()))
idx, t = 0, 0
for i in range(n-1):
    for j in range(i+1, n):
        if j == i+1:
            idx = j
        elif data[idx] > data[j]:
            idx = j
    if data[i] > data[idx]:
        data[i], data[idx] = data[idx], data[i]
        t += 1
print(" ".join(map(str, data)))
print(t)

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


def selectionSort(nums):
    count=0
    for i in range(len(nums)):
        minj=i
        for j in range(i,len(nums)):
            if int(nums[j])<int(nums[minj]):
                minj=j
        if i!=minj:          
            tmp=nums[minj]
            nums[minj]=nums[i]
            nums[i]=tmp
            count+=1
    print(' '.join(nums))
    print(count)


selectionSort(nums)

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

if __name__ == '__main__':
    length = input()
    data = [int(x) for x in input().split()]
    data_s, c = sSort(data)
    print (' '.join([str(x) for x in data_s]))
    print (c)

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

Solution (Python):



import sys

def selection_sort(A):
    swap_count = 0
    for i in range(len(A)):
        mini = i
        min_val = min(A[i:])
        min_index = A[i:].index(min_val) + i

        if A[min_index] < A[i]:
            swap_count += 1
            A[min_index], A[i] = A[i], A[min_index]

    return swap_count


n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

swap_count = selection_sort(A)
s_list = list(map(str, A))
print(' '.join(s_list))
print(swap_count)

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