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

Solution (Python):
n = int(input())
a = [int(_) for _ in input().split()]
count = 0
for i in range(n-1):
    tmp_index = i
    for j in range(i+1, n):
        
        
        if a[j] < a[tmp_index]:
            tmp_index = j
    if tmp_index != i:
        count += 1
        
        a_tmp = a[i]
        a[i] = a[tmp_index]
        a[tmp_index] = a_tmp
for i in range(n-1):
    print(a[i], end=" ")
print(a[n-1])
print(count)

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


if __name__ == "__main__":
    main()

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

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

Solution (Python):
cnt = int(input())
numbers = list(map(int, input().split(' ')))


def selectionsort(A, N):
    '''
    :param A: N個の要素を含む０オリジンの配列
    :param N: Aの要素数
    :return:
    '''
    swap_cnt = 0

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

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

    return ' '.join(map(str, A)), swap_cnt

numbers, swap_cnt = selectionsort(numbers, cnt)
print(numbers)
print(swap_cnt)

Solution (Python):

def selection_sort(array):
    A = array[:]
    count = 0
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if int(A[j]) < int(A[mini]):
                mini = j
        if i != mini:
            A[i], A[mini] = A[mini], A[i]
            count += 1

    return A, count

_, array = input(), input().split()

result, count = selection_sort(array)

print(' '.join(result))
print(count)

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

s_count = 0
i = 0

while i < N:

    min_j = i
    j = i

    while j < N:

        if A[j] < A[min_j]:

            min_j = j

        j += 1

    A[i], A[min_j] = A[min_j], A[i]

    if i != min_j :
        s_count += 1

    i += 1

s = ''

for x in A:

    s = s + str(x) + ' '

print(s.rstrip())
print(s_count)

Solution (Python):
def SelectionSort(A):
    n = len(A)
    ans = 0
    for i in range(n-1):
        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]
            ans += 1
    print(' '.join([str(i) for i in A]))
    print(ans)

_ = input()
SelectionSort([int(i) for i in input().split()])

Solution (Python):
def s_sort(l):
    q = len(l)
    count = 0
    for i in range(q):
        minv = i
        for j in range(i+1, q):
            if l[j] < l[minv]:
                minv = j
        if minv != i:
            l[i], l[minv] = l[minv], l[i]
            count += 1
    print(' '.join(map(str, l)))
    print(count)


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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
swap_counter = 0
for i in range(N):
    min_temp = i
    for j in range(i, N, 1):
        if A[j] < A[min_temp]:
            min_temp = j
    if i < min_temp:
        A[i], A[min_temp] = A[min_temp], A[i]
        swap_counter += 1
A_str = [str(a) for a in A]
result = ' '.join(A_str)
print(result)
print(swap_counter)

Solution (Python):
def selection_sort(nums, n):
    c = 0

    for i in range(n):
        minj = i

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

        if i != minj:
            nums[i], nums[minj] = nums[minj], nums[i]
            c += 1

    return (c, nums)

def main():
    n = int(input())
    nums = [int(x) for x in input().split()]

    c, nums = selection_sort(nums, n)

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

if __name__ == '__main__':
    main()

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


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

Solution (Python):
def selection_sort(lis, l):
    times = 0
    for i in range(0, l - 1):
        minj = i
        minj_cp = minj
        for j in range(i, l):
            if lis[j] < lis[minj]:
                minj = j
        if minj_cp != minj:
            times += 1
        ele = lis[i]
        lis[i] = lis[minj]
        lis[minj] = ele
    return times

inputs = []
while True:
    try:
        inputs.append(input())
    except(EOFError):
        break

ln = int(inputs[0])
li = list(map(int, inputs[1].split()))

t = selection_sort(li, ln)

print(*li)
print(t)

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
        v = A[i]
        A[i] = A[minj]
        A[minj] = v
print(*A)
print(cnt)

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()))

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

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

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

Solution (Python):

def selection_sort(A,N):
    counter = 0
    for i in range(0,N):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        if not i == minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            counter += 1
    return counter
N = int(input())
A = [int(i) for i in input().split(' ')]
c = selection_sort(A,N)
print(' '.join(list(map(str, A))))
print(c)