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: Wrong Answer

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
        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 range(n)]
    result = selectionSort(data,n)
    print(" ".join(map(str,data)))
    print(result)

Submission status: Wrong Answer

Solution code:
# insertionSort                                                
# divide list into ordered part and part wait to sort          
# select one from part wait to sort and insert into ordered part                                                              
global r, signals                                              
r, signals = 0, False                                          
def insertionSort(A):                                          
    global r, signals                                          
    # Get length of A                                          
    l = len(A)                                                 
    for i in range(l):                                         
        # Selected i-th element to swap from 0 to n            
        v = A[i]                                               
        # j is point to tail of order                          
        j = i - 1                                              
        # Move forward, Control order of sorted                
        while j >= 0 and A[j] > v:                             
            A[j+1] = A[j]                                      
            j -= 1                                             
            signals = True                                     
        A[j+1] = v                                             
        r += 1 if signals else 0                               
        signals = False                                        
    return A                                                   
                                                               
raw_input()                                                    
res, l = "", 0                                                 
for i in insertionSort(map(int, raw_input().split())):         
    res += (" " if l != 0 else "") + str(i)                    
    l += 1                                                     
print res
print r

Submission status: Wrong Answer

Solution code:
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
        pretty_sequence(seq)
    return seq, count

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

Submission status: Wrong Answer

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

for i in range(N - 1) :
    minj = N - 1
    for j in range(i, N - 1) :
        if A[j] < A[minj] :
            minj = int(j)
    if A[i] != A[minj] :
        tem  = int(A[i])
        A[i] = int(A[minj])
        A[minj] = int(tem)
        cou = cou + 1
A   = [str(temp) for temp in A]
print(' '.join(A))
print(cou)

Submission status: Wrong Answer

Solution code:
#3.4

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

swapCount = 0
for i in range(0, N):
    minIndex = i
    for j in range(0, 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)

Submission status: Wrong Answer

Solution code:
#3.4

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

swapCount = 1
for i in range(0, N):
    minIndex = i
    for j in range(0, 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)

Submission status: Wrong Answer

Solution code:
#3.4

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

swapCount = 0
for i in range(0, N):
    minIndex = i
    for j in range(0, 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)

Submission status: Wrong Answer

Solution code:
#ALDS1_2-B Sort 1 - Selection Sort
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
        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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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]
            chge = 1
    if chge:
        idx = A.index(mn)
        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)

Submission status: Wrong Answer

Solution code:
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]
            chge = 1
    if chge:
        idx = A.index(mn)
        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)

Submission status: Wrong Answer

Solution code:
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]
            chge = 1
    if chge:
        idx = A.index(mn)
        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)

Submission status: Wrong Answer

Solution code:
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):
        print(mn, A[j])
        if mn > A[j]:
            mn = A[j]
            chge = 1
    if chge:
        idx = A.index(mn)
        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)

Submission status: Wrong Answer

Solution code:
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):
        print(mn, A[j])
        if mn > A[j]:
            mn = A[j]
            chge = 1
    if chge:
        idx = A.index(mn)
        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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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
                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()

Submission status: Wrong Answer

Solution code:
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
        swap(array, min_index, index)

print list_to_string(array)
print str(swap_num)

Submission status: Wrong Answer

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

for i in range(N):
    # i ?????????????????¨????????????
    minj = i
    for j in range(i, N):
        # ?????????????????¨??????????°???????????????????
        if A[j] < A[minj]:
            minj = j
    # ??????????????¨??????????°????????????????????????\????????????
    A[i], A[minj] = A[minj], A[i]
    cnt += 1

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

change = 0
new = []
for idx in range(n):
	idx_min = data.index(min(data[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)

Submission status: Wrong Answer

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


for i in range(n):
    minj = k[i]

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


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

Submission status: Wrong Answer

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


for i in range(n):
    minj = k[i]

    for j in range(i,n):
        if minj > k[j]:
            minj = k[j]
            k[j]=k[i]

        t = k[i]
        k[i] = minj
    if t != minj:
        m += 1



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

Submission status: Wrong Answer

Solution code:
def selectionSort(nums):
    k=0
    for i,n in enumerate(nums):
        try:
            m=min(nums[i+1:])
            j=nums.index(m)
            if n>m:
                nums[i],nums[j]=nums[j],nums[i]
                k+=1
        except:
            continue
    return nums,k
    
n=int(input())
nums=list(map(int,input().split()))

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

Submission status: Wrong Answer

Solution code:
"""
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] ?????????
"""

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

N=int(input())
A=input().split()
t=sort(A,N)
for i in range(N):
    print(A[i],end=' ')
print('\b\n'+str(t))

Submission status: Wrong Answer

Solution code:
"""
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]
"""
import logging
logging.basicConfig(level=logging.WARNING,format=' %(asctime)s - %(levelname)s - %(message)s')

def sort(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
        tmp=A[i]
        A[i]=A[mini]
        A[mini]=tmp
        count+=1
    return count

A=[]
n=int(input())
for i in range(n):
    A.append(int(input()))
    logging.info('A[{}] = {}'.format(i,A[i]))
t=sort(A)
for i in range(n):
    print(A[i],end=' ')
print('\b\n'+str(t))

Submission status: Wrong Answer

Solution code:
"""
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]
"""
import logging
logging.basicConfig(level=logging.WARNING,format=' %(asctime)s - %(levelname)s - %(message)s')

def sort(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
        tmp=A[i]
        A[i]=A[mini]
        A[mini]=tmp
        count+=1
    return count

A=[]
n=int(input())
logging.info('n={}'.format(n))
for i in range(n):
    A=input().split()
    logging.info('A[{}] = {}'.format(i,A[i]))
t=sort(A)
for i in range(n):
    print(A[i],end=' ')
print('\b\n'+str(t))

Submission status: Wrong Answer

Solution code:
dummy = input()

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

print(s_list)

count = 0
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)

Submission status: Wrong Answer

Solution code:
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]
    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)

Submission status: Wrong Answer

Solution code:
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
        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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

if __name__ == '__main__' :
    main()

Submission status: Wrong Answer

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

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

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

if __name__ == '__main__' :
    main()

Submission status: Wrong Answer

Solution code:
def bubbleSort(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[j], A[j - 1] = A[j - 1], A[j]
                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()]

bubbleSort(a, n)

Submission status: Wrong Answer

Solution code:
def bubbleSort(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[j], A[minj] = A[minj], A[j]
                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()]

bubbleSort(a, n)

Submission status: Wrong Answer

Solution code:
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]
        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)

Submission status: Wrong Answer

Solution code:
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()
A=[int(s) for s in input.split(' ')]
t=selectsort(A)
print (A,t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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
        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)

Submission status: Wrong Answer

Solution code:
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(ans[0])
    print(ans[1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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;
        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);

Submission status: Wrong Answer

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


def selectionSort(nums,n):
    count=0
    for i in range(n):
        minj=i
        for j in range(i+1,n):
            if nums[j]<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,n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def selectionSort(A,N):
  
    count = 0
    for i in range(N):
        
        minj = i
        
        for j in range(i,N,1):
           
            if A[j] < A[minj]:
                minj = j
                
        
        if minj != i:
            count = count + 1
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            print(' '.join(map(str,A)))
    print(count)
    
N = int(input())
A = input()
A = list(map(int,A.split()))   
selectionSort(A,N)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(e) for e in input().split()]

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

    print(A)
    print(steps)
    return A

selection_sort(A, N)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(e) for e in input().split()]

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

    print(A)
    print(steps)
    return A

selection_sort(A, N)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(e) for e in input().split()]

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

    print(A)
    print(steps)
    return A

selection_sort(A, N)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    v = a[i]
    j = a[i:].index(min(a[i:]))+i
    w = a[j]
    v, w = w, v
    if i != j:
        ans+=1


print(a)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    v = a[i]
    j = a[i:].index(min(a[i:]))+i
    w = a[j]
    v, w = w, v
    if i != j:
        ans+=1


print(*a)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    v = a[i]
    j = a[i:].index(min(a[i:]))+i
    w = a[j]
    v, w = w, v
    if i != j:
        ans+=1


print(*a)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    v = a[i]
    j = a[i:].index(min(a[i:]))+i
    w = a[j]
    v, w = w, v
    if i != j:
        ans +=1


print(*a)
print(ans)

Submission status: Wrong Answer

Solution code:
x = int(input())
*li, = map(int, input().split())

mi_li = li.copy()
ans = 0
for i in range(x):
    where = 0
    where2 = 0
    min_li = min(mi_li)
    for j in range(len(mi_li)):
        if min_li == mi_li[j]:
            where = j
            break
    for k in range(len(li)):
        if min_li == li[k]:
            where2 = k
            break
    if i < x-1 and li[i] > min_li:
        li[i], li[where2], mi_li[where], mi_li[0] = mi_li[where], li[i], li[i], li[where2]
        del mi_li[0]
        ans += 1

print(*li)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
cnt = 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]
        cnt +=1

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

Submission status: Wrong Answer

Solution code:
def selectionSort(A, N): # N個の要素を含む0-オリジンの配列A
    A = A.split(" ")
    change_count = 0
    #for i が 0 から N-1 まで
    for i in range(N):
        minj = i
        #for j が i から N-1 まで
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        #A[i] と A[minj] を交換
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            change_count+=1
    
    return A, change_count

# 入力
N = int(input("数列の長さを表す整数を入力して下さい  "))  # 数列の長さを表す整数（N）
A = input("N 個の整数が空白区切りで入力して下さい  ")   # N個の整数が空白区切り
sorted_list, change_count = selectionSort(A,N)

# 回答
print(" ".join(map(str,sorted_list)))
print(change_count)

Submission status: Wrong Answer

Solution code:
def selectionSort(A, N): # N個の要素を含む0-オリジンの配列A
    A = A.split(" ")
    change_count = 0
    #for i が 0 から N-1 まで
    for i in range(N):
        minj = i
        #for j が i から N-1 まで
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        #A[i] と A[minj] を交換
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            change_count+=1
    
    # 回答
    print(" ".join(map(str,A)))
    print(change_count)
    return True

# 入力
N = int(input("数列の長さを表す整数を入力して下さい  "))  # 数列の長さを表す整数（N）
A = input("N 個の整数が空白区切りで入力して下さい  ")   # N個の整数が空白区切り
selectionSort(A,N)

Submission status: Wrong Answer

Solution code:
def selectionSort(A, N): # N個の要素を含む0-オリジンの配列A
    A = A.split(" ")
    change_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] を交換
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            change_count+=1
    
    # 回答
    print(" ".join(map(str,A)))
    print(change_count)
    return True

# 入力
N = int(input("数列の長さを表す整数を入力して下さい  "))  # 数列の長さを表す整数（N）
A = input("N 個の整数が空白区切りで入力して下さい  ")   # N個の整数が空白区切り
selectionSort(A,N)

Submission status: Wrong Answer

Solution code:
def selectionSort(A, N): # N個の要素を含む0-オリジンの配列A
    A = A.split(" ")
    change_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] を交換
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            change_count+=1
    
    # 回答
    print(" ".join(map(str,A)))
    print(change_count)
    #return True

# 入力
N = int(input("数列の長さを表す整数を入力して下さい  "))  # 数列の長さを表す整数（N）
A = input("N 個の整数が空白区切りで入力して下さい  ")   # N個の整数が空白区切り
selectionSort(A,N)