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] 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



Sample input:
6
5 6 4 2 1 3


Sample output:
1 2 3 4 5 6
4

Submission status: Accepted

Solution code:
factor = int(input())
numbers = list(map(int,input().split()))

def selectionsort(array,n):
    counter = 0
    for i in range(len(array)):
        minj = i
        for j in range(i,len(array)):
            if array[j] < array[minj]:
                minj = j
        array[minj],array[i] = array[i],array[minj]
        if minj != i :
            counter += 1
    return counter

repetition = selectionsort(numbers,factor)
print(" ".join(list(map(str,numbers))))
print(repetition)

Submission status: Accepted

Solution code:
N = int(input())
A = input()
B = A.split()
total = 0
for i in range(N) :
    mini = int(i)
    for j in range(i, N) :
        if int(B[j]) < int(B[mini]) :
            mini = int(j)
    if mini != int(i) :
        B[i], B[mini] = B[mini], B[i]
        total += 1
print(" ".join(B))
print(total)

Submission status: Accepted

Solution code:
def swap(a, i, j):
    # list aのi番目の要素とj番目の要素を交換する関数
    k = a[j]
    a[j] = a[i]
    a[i] = k


def selectionSort(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 i != minj:
            sw += 1
        swap(a,i,minj)
    print(' '.join(list(map(str, a))))
    print(sw)


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

Submission status: Accepted

Solution code:
n = int(input())
cards = list(map(int,input().split()))
cnt = 0
for i in range(n):
    minj = i
    for j in range(i,n):
        if cards[minj] > cards[j]:
            minj = j
    if i != minj:
        cnt += 1
    cards[i], cards[minj] = cards[minj], cards[i]


print(*cards)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list_size = input()                                                                                                                                                                                         
list_str = input()                                                                                                                                                                                          
val_list = list(map(int, list_str.split()))                                                                                                                                                                 
                                                                                                                                                                                                            
def where_is_the_first_lowest_val(List):                                                                                                                                                                    
    return List.index(min(List))                                                                                                                                                                            
                                                                                                                                                                                                            
def swap(idx_num, lowest_val_index, List):                                                                                                                                                                  
    val = List[idx_num]                                                                                                                                                                                     
    List[idx_num] = List[lowest_val_index + idx_num]                                                                                                                                                        
    List[lowest_val_index + idx_num] = val                                                                                                                                                                  
                                                                                                                                                                                                            
swap_num = 0                                                                                                                                                                                                
for idx_num in range(0, int(list_size) - 1):                                                                                                                                                                
    unsorted_list = val_list[idx_num : int(list_size)]                                                                                                                                                      
    lowest_val_index = where_is_the_first_lowest_val(unsorted_list)                                                                                                                                         
    if val_list[idx_num] != val_list[lowest_val_index + idx_num]: swap(idx_num, lowest_val_index, val_list) ; swap_num += 1                                                                                 
                                                                                                                                                                                                            
str_list = list(map(str, val_list))                                                                                                                                                                         
str_list = ','.join(str_list).replace(',', ' ')                                                                                                                                                             
print(str_list)                                                                                                                                                                                             
print(swap_num)

Submission status: Accepted

Solution code:
def selectionSort(A, N):
    count = 0
    for i in range(0, N):
        minj = i
        flag = 0
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
                flag = 1
        if flag == 1:
            count += 1
        v = A[i]
        A[i] = A[minj]
        A[minj] = v

    return A, count

N = input()

line = raw_input()
line = line.strip().split()
line = map(lambda x: int(x), line)
a = selectionSort(line, N)

print(' '.join(map(lambda x: str(x), a[0])))
print(a[1])

Submission status: Accepted

Solution code:
# coding: utf-8

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

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 i != minj:
            count += 1
    return count

n = int(input().rstrip())
a = list(map(int,input().rstrip().split()))
c = selectionSort(a, n)
printA(a, n)
print(c)

Submission status: Accepted

Solution code:
def selection_sort(A: list, N:int) -> list:
    """
    :A[N]: サイズがNの整数型配列。
    :i: 未ソートの部分の先頭を指すループ変数で、配列の先頭から末尾に向かって移動する。
    :minj: 各ループの処理でi 番目からN-1 番目までの要素で最小のものの位置。j 未ソートの部分から最小値の位置（minj）を探すためのループ変数。
    """
    count = 0

    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        # alter position
        if(i != minj):
            a, b = A[i], A[minj]
            A[i], A[minj] = b, a
            count += 1

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

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

Submission status: Accepted

Solution code:
def selection_sort(array):
    N = len(array)
    exc_time = 0
    for i in range(N):
        min_index = i
        for j in range(i, N):
            if array[min_index] > array[j]:
                min_index = j
        if min_index != i:
            array[i], array[min_index] = array[min_index], array[i]
            exc_time += 1
    return exc_time
    
def putsarray(array):
    for i in range(len(array) - 1):
        print(array[i], end=' ')
    print(array[-1])

if __name__ == "__main__":
    N = int(input())
    array = input().split()
    array = [int(n) for n in array]
    exc = selection_sort(array)
    putsarray(array)
    print(exc)

Submission status: Accepted

Solution code:
def show(nums):
    for i in range(len(nums)):
        if i!=len(nums)-1:
            print(nums[i],end=' ')
        else:
            print(nums[i])
def selectionSort(A,N):
    count=0
    for i in range(N):
        minj = i
        for j in range(i+1,N):
            if A[j] < A[minj]:
                minj = j
        if A[i]>A[minj]:
            A[i],A[minj]=A[minj],A[i]
            count+=1
    show(A)
    print(count)
N = int(input())
A = list(map(int,input().split()))
selectionSort(A,N)

Submission status: Accepted

Solution code:
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=count+1
print(" ".join(map(str,a)))
print(count)

Submission status: Accepted

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

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

counter = 0

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

show(A)
print(counter)

Submission status: Accepted

Solution code:
def selectionSort(A,N):
    '''list of int, int -> list of int
    return sorted list(selection sort)
    '''
    assert(len(A) == N)
    outA = A.copy()
    cnt = 0
    for i in range(N):
        minj = i
        for j in range(i, N):
            if outA[j] < outA[minj]:
                minj = j
        outA[i], outA[minj] = outA[minj], outA[i]
        if i != minj:
            cnt += 1
    return outA, cnt
def printlist(L):
    for itm in L[:-1]:
        print(itm, end = ' ')
    print(L[-1])

n = int(input())
A = list(map(int, input().split()))
A, num = selectionSort(A, n)
printlist(A)
print(num)

Submission status: Accepted

Solution code:
num = int(input())

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

for i in range(0, num):
        minID = i
        for j in range(i, num):
                if A[j] < A[minID]:
                        minID = j
        if i != minID:
                A[i],  A[minID] = A[minID], A[i]
                count += 1

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

Submission status: Accepted

Solution code:
def selection_sort(A):
    count = 0
    for i in range(len(A)):
        minv = 101
        minj = -1
        for j in range(i, len(A)):
            if minv > A[j]:
                minv = A[j]
                minj = j
        if A[i] != A[minj]:
            A[i], A[minj] = A[minj], A[i]
            count += 1

    return count


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

count = selection_sort(A)

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

Submission status: Accepted

Solution code:
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[j]<a[m]:m=j
 if m!=i:a[i],a[m]=a[m],a[i];c+=1
print(*a)
print(c)

Submission status: Accepted

Solution code:
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 i != minj: count += 1
    printArray(a)
    print(count)


#配列の出力
def printArray(array):
    print(' '.join(map(str, array)))

###----------mainここから---------------

#配列の要素数と要素の入力
n = int(input())
a = list(map(int, input().split()))

selectionSort(a, n)

Submission status: Accepted

Solution code:
def selectionSort(L, n):
  cnt = 0
  for i in range(n):
    minj = i
    for j in range(i, n):
      if L[j] < L[minj]:
        minj = j
    L[i], L[minj] = L[minj], L[i]
    if i != minj:
      cnt += 1
  return L, cnt

N = int(input())
A = list(map(int, input().split()))
A, t = selectionSort(A, N)
print(' '.join(map(str, A)), t, sep='\n')

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(n):
    minj = i
    for j in range(i, n):
        if A[j] < A[minj]:
            minj = j
    if minj > i:
        A[i], A[minj] = A[minj], A[i]
        count += 1
print(*A)
print(count)

Submission status: Accepted

Solution code:
N = int(input())
I = list(map(int, input().split()))
cnt = 0
for i in range(N):
    min_index = i
    for j in range(i, N):
        if (I[j] < I[min_index]):
            min_index = j
    if (min_index != i):
        tmp = I[i]
        I[i] = I[min_index]
        I[min_index] = tmp
        cnt += 1

print(str(I).replace(',','').replace('[','').replace(']',''))
print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
count=0
a=list(map(int,input().split()))

for i in range(n):
    min=a[i]
    k=i
    for j in range((i+1),n):
        if min > a[j]:
            min=a[j]
            k=j
    if k!=i :
        a[i],a[k]=a[k],a[i]
        count+=1

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

Submission status: Accepted

Solution code:
def sort(A):
    global c
    c=0 
    for i in range(0,len(A)-1):
        selection(A,i)
        
    return A

def selection(A,i):
    global c
    min=i
    for j in range(i+1,len(A)):
        if A[min]>A[j]:
            min=j
            
            
    A[i],A[min]=A[min],A[i]
    if not A[i]==A[min]:
        c+=1
    
    
n=int(input())
A=list(map(int,input().split()))

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

Submission status: Accepted

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


n = int(input())
a = [int(i) for i in input().split()]
count = selectionSort(a, n)
print(" ".join(map(str, a)))
print(count)

Submission status: Accepted

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

print(*A)
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 选择排序
def showList(list1):
  for i in range(len(list1)):
    if(i<len(list1)-1):
      print(list1[i],end=' ')
    else:
      print(list1[i])
      
def selectionSort(seq):
  swapCount = 0
  for i in range(len(seq)):
    minIndex = i
    for j in range(i+1,len(seq)):
      if seq[minIndex]>seq[j]:
        minIndex = j
    if i!=minIndex:
      seq[i],seq[minIndex] = seq[minIndex],seq[i]
      swapCount+=1
  return swapCount

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

count = selectionSort(list1)
showList(list1)
print(count)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int, input().strip().split(' ')))

count = 0

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

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

print(count)

Submission status: Accepted

Solution code:
def selectionSort(A, N): # N個の要素を含む0-オリジンの配列A
    counter = 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:
            counter += 1
    return A, counter

if __name__ == '__main__':
    N = int(input())
    a = list(map(int, input().split()))
    a, num = selectionSort(a, N)
    for i in range(len(a)):
        if i != len(a)-1:
            print(a[i], end=" ")
        else:
            print(a[i])
    print(num)

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

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

print(*A)
print(count)

Submission status: Accepted

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

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 i != minj:
            count += 1
    return count

c = selectionSort(A, N)
for i in range(len(A)):
    if i != len(A) - 1:
        print(A[i], end=" ")
    else:
        print(A[i])
print(c)

Submission status: Accepted

Solution code:
def printer(A):
    ret = str(A[0])
    for i in range(1, len(A)):
        ret += " " + str(A[i])
    print(ret)
    return True


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

ans = 0
for i in range(n):
    minj = i
    for j in range(i, n):
        if A[minj] > A[j]:
            minj = j
    if i != minj:
        ans += 1
        tmp = A[i]
        A[i] = A[minj]
        A[minj] = tmp
printer(A)
print(ans)

Submission status: Accepted

Solution code:
import sys


def selection_sort(a, n):
    swap_count = 0
    for i in range(0, n):
        minj = min(range(i, n), key=a.__getitem__)
        if i != minj:
            a[i], a[minj] = a[minj], a[i]
            swap_count += 1
    return swap_count


n = int(sys.stdin.readline())
a = [int(v) for v in sys.stdin.readline().strip().split()]
count = selection_sort(a, n)

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

Submission status: Accepted

Solution code:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B&lang=jp
# Selection Sort: python3
#  2018.12.09 yonezawa

import sys
input = sys.stdin.readline


def selectionSort(l):
    cnt= min_i= 0
    for i in range(len(l)-1):
        min_i = i
        flg = False
        for j in range(i+1,len(l)):
            if l[min_i] > l[j]:
                min_i = j
                flg = True
        if flg == True:
            cnt += 1
            #print (l[i],l[min_i])
            (l[i],l[min_i]) = (l[min_i],l[i]) 
    return l,cnt

def main():
    n = int(input())
    l = list(map(int,input().split()))
    (ans,cnt) = selectionSort(l)
    print (*ans)
    print (cnt)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def selectionSort(A, N):
	global cnt

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

	return A

if __name__ == '__main__':
	n = int(input())
	R = list(map(int, input().split()))
	cnt = 0
	R = selectionSort(R, n)
	print(" ".join(map(str, R)))
	print(cnt)

Submission status: Accepted

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


def selection_sort(Ary):
    N = len(Ary)
    count = 0
    for i in range(N-1):
        min_j = i
        flag = 0
        for j in range(N-i):
            if Ary[j+i] < Ary[min_j]:
                min_j = j+i
                flag = 1
        Ary[i], Ary[min_j] = Ary[min_j], Ary[i]
        if flag == 1:
            count += 1
            flag = 0
    return Ary, count

A_sorted , count = selection_sort(A)
print(' '.join(map(str, A_sorted)))
print(count)

Submission status: Accepted

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

k = 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:
        k += 1
        t = a[i]
        a[i] = a[minj]
        a[minj] = t
for i in range(0, n - 1):
    print(a[i], end=' ')
print(a[n - 1])
print(k)

Submission status: Accepted

Solution code:

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

flag = 1 #一度でも入れ替えをした
cnt = 0
point = 0
while point < N:
    rpoint = point
    for i in range(point,N,1):
        if A[rpoint] > A[i]:
            rpoint = i
    A[point], A[rpoint] = A[rpoint], A[point]
    if point != rpoint:
        cnt += 1
    point += 1

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

Submission status: Accepted

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

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

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

print()
print(cnt)

Submission status: Accepted

Solution code:
def selectionsort(n,a):
    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

if __name__ == '__main__':
    n = int(input())
    a = [int(x) for x in input().split()]
    a, count = selectionsort(n,a)
    print(' '.join(map(str, a)))
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

a = input().split()

a = [int(x) for x in a]

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

for i,x in enumerate(a):
    if i != len(a)-1:
        print(x, end=" ")
    else:
        print(x, end="")
print()
print(count)

Submission status: Accepted

Solution code:
n=int(input())
lst=list(map(int,input().split()))
count=0
for i in range(n-1):
    minlst=min(lst[i:])
    if lst[i]==minlst:continue
    count+=1
    for j in range(i+1,n):
        if minlst==lst[j]:
            lst[i],lst[j]=lst[j],lst[i]
            break
print(*lst)
print(count)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
change=0

def hyouji(a,change):
    for i in range(len(a)):
        if i==0:
            print(a[i],end="")
        else:
            print(" "+str(a[i]),end="")
    print()
    print(change)


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

hyouji(a,change)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
selection sort
"""
N = int(input())
aN = list(map(str, input().split()))

cnt = 0
for i in range(N):
    minj = i
    for j in range(i, N):
        if int(aN[j]) < int(aN[minj]):
            minj = j
    if i != minj:
        tmp = aN[i]
        aN[i] = aN[minj]
        aN[minj] = tmp
        cnt += 1
print(' '.join(aN))
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
*A, = map(int, input().split())
cnt = 0
for i in range(N):
    min = i
    for j in range(i, N):
        if A[min]  > A[j]:
            min = j
    if min != i:
        A[i], A[min] = A[min], A[i]
        cnt += 1
print(*A)
print(cnt)

Submission status: Accepted

Solution code:
def selection_sort(num_list):
    cnt = 0

    for i in range(len(num_list)-1):
        min_idx = i
        for j in range(i,len(num_list)):
            if num_list[j] < num_list[min_idx]:
                min_idx = j
        if i != min_idx:
            num_list[i],num_list[min_idx] = num_list[min_idx],num_list[i]
            cnt += 1
    return cnt

n = int(input())
num_list = list(map(int,input().split()))
ans = selection_sort(num_list)
ans_list = [str(i) for i in num_list]

print(' '.join(ans_list))
print(ans)

Submission status: Accepted

Solution code:
def solve():
    size = int(input())
    array = list(map(int, input().split()))
    SelectionSort(array, size)


def SelectionSort(array, size):
    swap_count = 0
    for i in range(0, size, 1):
        minj = i
        for j in range(i, size, 1):
            if array[j] < array[minj]:
                minj = j
        if array[i] is not array[minj]:
            array[i], array[minj] = array[minj], array[i]
            swap_count += 1
    print(' '.join(map(str, array)))
    print(swap_count)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def selection_sort(n, nums):
    cnt = 0
    for i in range(n):
        minj = i
        for j in range(i, n):
            if nums[j] <  nums[minj]:
                minj=j
        if i != minj:              
            tmp = nums[i]
            nums[i] = nums[minj]
            nums[minj] = tmp
            cnt += 1
            
    print(' '.join(map(str, nums)))
    print(cnt)

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

    selection_sort(n, nums)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def SelectionSort(A):
    swapCount=0
    # sort
    for i in range(len(A)):
        mini=i
        for j in range(i,len(A)):
            if A[j]<A[mini]:
                mini=j
        if mini!=i:
            tmp=A[i]
            A[i]=A[mini]
            A[mini]=tmp
            swapCount+=1
    return swapCount
    

# input
n=int(input())
nums=list(map(int, input().split()))
count=SelectionSort(nums)
maplist=map(str, nums)
print(' '.join(maplist))
print(count)

Submission status: Accepted

Solution code:
n = int(input())

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

cnt = 0

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

for i in range(n):
    if i == n-1:
        print(blist[i])
    else:
        print(str(blist[i]) + " ", end="")

print(cnt)

Submission status: Accepted

Solution code:
import sys

def main():
    inputslen = int(sys.stdin.readline().rstrip())
    inputs= sys.stdin.readline()

    sortvalue = [int(i) for i in inputs.split()]
    count = 0
    for i in range(0, inputslen-1):

        minidx = i
        for j in range(i, inputslen):
            if sortvalue[j] < sortvalue[minidx]:
                minidx = j
        if sortvalue[minidx] != sortvalue[i]:
            minvalue = sortvalue[minidx]
            sortvalue[minidx] = sortvalue[i]
            sortvalue[i] = minvalue
            count += 1

    printvalue = map(str, sortvalue)
    print(' '.join(printvalue))
    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
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
print(*A)
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,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 minj != i:
        a[i],a[minj] = a[minj],a[i]
        swap_count += 1
print(" ".join(map(str,a)))
print(swap_count)

Submission status: Accepted

Solution code:
class Selection_sort:
    def __init__(self):
        self.swap_num=0
    
    def sort(self,data):
        for i in range(len(data)):
            mini=i
            for j in range(i+1,len(data)):
                if(data[j] < data[mini]):
                    mini=j
            if(mini!=i):
                data[i],data[mini]=data[mini],data[i]
                self.swap_num+=1
        return data






n=int(input())
data=list(map(int,input().split()))
selection_sort=Selection_sort()
print(" ".join(list(map(str,selection_sort.sort(data)))))
print(selection_sort.swap_num)

Submission status: Accepted

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

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

for k in range(N):
        if k > 0:
            print(' ', end='')
        print(A[k], end='')

print('')
print(count)

Submission status: Accepted

Solution code:
def print_list(r):
    for i in range(len(r)):
        if i != len(r)-1:
            print (r[i], end=' ')
        else:
            print(r[i])


n=int(input())
r=list(map(int,input().split()))
count_num = 0
for i in range(0, n):
    minj = i
    for j in range(i, n):
        if r[j] < r[minj]:
            minj = j
    v = r[minj]
    r[minj] = r[i]
    r[i] = v
    if minj != i:
        count_num += 1
print_list(r)
print(count_num)