s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
int64
0
100
memory
stringlengths
4
6
code_size
int64
15
14.7k
code
stringlengths
15
14.7k
problem_id
stringlengths
6
6
problem_description
stringlengths
358
9.83k
input
stringlengths
2
4.87k
output
stringclasses
807 values
__index_level_0__
int64
1.1k
1.22M
s036869316
p02255
u143447119
1544884888
Python
Python3
py
Accepted
30
5980
540
N = int(input()) A = list(map(int, input().split())) def insertionSort(A, N): for k in range(len(A)): if k != len(A) - 1: print(A[k], end=" ") else: print(A[k]) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,682
s504277553
p02255
u665008200
1544329315
Python
Python3
py
Accepted
20
5600
357
def list_print(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())) list_print(A) for i in range(1, n): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,683
s686716480
p02255
u674879863
1544283419
Python
Python3
py
Accepted
20
5612
385
import sys def insertion_sort(a): print(' '.join(map(str, a))) for i in range(1, len(a)): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j + 1] = a[j] j -= 1 a[j + 1] = v print(' '.join(map(str, a))) n = int(sys.stdin.readline()) a = [int(v) f...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,684
s665601655
p02255
u077168966
1544273037
Python
Python3
py
Accepted
20
5604
329
def insertionSort(At, Nt): for i in range(Nt): v = At[i] j = i - 1 while j >= 0 and At[j] > v: A[j + 1] = A[j] j = j - 1 A[j + 1] = v print(" ".join(map(str,At))) return At if __name__ == '__main__': N = int(input()) A = list(map(int, input().split())) A = insertionSort(A, N) #print(" ".join(map(...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,685
s826861695
p02255
u600395583
1544089980
Python
Python3
py
Accepted
20
5600
458
n = int(input()) sortlist = list(map(int,input().split())) print(' '.join(map(str, sortlist))) for i in range(1,n): temp = sortlist[i] if temp < sortlist[i-1]: j = i while True: sortlist[j] = sortlist[j-1] j -= 1 if j ==0 or temp >= sortlist[j-1]: ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,686
s602055412
p02255
u237270455
1543900203
Python
Python3
py
Accepted
20
5976
208
N=int(input()) A=[int(i) for i in input().split()] print(*A) for i in range(1, len(A)): key = A[i] j = i-1 while j>=0 and A[j]>key: A[j+1]=A[j] j -= 1 A[j+1]=key print(*A)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,687
s981087581
p02255
u798796508
1543900135
Python
Python3
py
Accepted
30
5976
315
n = int(input()) a = list(map(int, input().split())) for i in range(0, n-1): print(a[i], end=" ") print(a[n-1]) for i in range(1, n): v = a[i] j = i-1 while j>=0 and a[j]>v: a[j+1] = a[j] j-=1 a[j+1] = v for i in range(0, n-1): print(a[i], end=" ") print(a[n-1])
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,688
s674559552
p02255
u803657704
1543897960
Python
Python3
py
Accepted
20
5604
413
def nsertionSort(A, N): #N個の要素を含む0-オリジンの配列A print(" ".join(map(str,A))) for i in range(1,N,1): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j-=1 A[j+1] = v print(" ".join(map(str,A))) if __name__ == "__main__": N = int(input...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,689
s295372390
p02255
u089116225
1543834088
Python
Python3
py
Accepted
20
5608
347
n = int(input()) a = [int(x) for x in input().split()] def printlist(l): print(' '.join(map(str, l))) def insertion_sort(a, n): for i in range(1, n): printlist(a) v = a[i] j = i-1 while j >= 0 and a[j] > v: a[j+1] = a[j] j -= 1 a[j+1] = v insert...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,690
s024647601
p02255
u036729444
1543501404
Python
Python3
py
Accepted
20
5608
285
n = int(input().strip()) a = [int(s) for s in input().strip().split(' ')] for i in range(1, n): print(' '.join((str(i) for i in a))) v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j+1] = a[j] j -= 1 a[j+1] = v print(' '.join((str(i) for i in a)))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,691
s680196102
p02255
u091332835
1543309894
Python
Python3
py
Accepted
20
5600
292
N = int(input()) A = list(map(int, input().split())) def insertion_sort(A, N): for i in range(N): v = A[i] j = i - 1 while j >= 0 and A[j]>v: A[j+1]=A[j] j -= 1 A[j+1] = v print(' '.join(map(str, A))) insertion_sort(A, N)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,692
s757145132
p02255
u482179998
1543286567
Python
Python3
py
Accepted
20
5984
169
cnt=int(input()) *card,=map(int,input().split()) for i in range(cnt): v=card[i] j=i-1 while j>=0 and card[j]>v: card[j+1]=card[j] j-=1 card[j+1]=v print(*card)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,693
s086072653
p02255
u754514998
1543231364
Python
Python3
py
Accepted
20
5596
333
def main(): n = int(input()) a = list(map(int, input().split())) printlist(a) insertionSort(a, n) def insertionSort(a, n): for i in range(1,n): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j + 1] = a[j] j -= 1 a[j+1] = v printlist(a) def printlist(a): values = map(str, a) print(' '.join(valu...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,694
s423637954
p02255
u831244171
1543179840
Python
Python3
py
Accepted
20
5604
372
def insertsort(array): for i in range(1,len(array)): print(" ".join(list(map(str,array)))) temp = array[i] j = i-1 while j >= 0 and temp < array[j]: array[j+1] = array[j] j -= 1 array[j+1] = temp return array input() a = insertsort(list(map(int,in...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,695
s882944053
p02255
u964933616
1543027822
Python
Python3
py
Accepted
30
6668
389
import copy n = int(input()) l = list(map(int, input().split())) s = copy.deepcopy(l) m = 1 print(*s) for i in range(1,n): count = 0 for j in range(0,m): if s[i] < l[j]: l.insert(j, l[i]) l.pop(i+1) m+=1 count += 1 break if count == 0: ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,696
s490444438
p02255
u127865499
1542689337
Python
Python3
py
Accepted
20
5596
235
N = int(input()) a = list(map(int,input().split())) x = ' '.join(map(str, a)) print(x) for i in range(1,N): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j+1] = a[j] j = j - 1 a[j+1] = v x = ' '.join(map(str, a)) print(x)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,697
s098320542
p02255
u820666857
1542612231
Python
Python3
py
Accepted
30
5976
459
n = int(input()) a = input().split() a = [int(x) for x in a] for i,x in enumerate(a): if i != len(a)-1: print(x, end=" ") else: print(x, end="") print() for i in range(1, len(a)): v = a[i] j = i-1 while j>= 0 and a[j] > v: a[j+1] = a[j] j -= 1 a[j+1] = v ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,698
s148688059
p02255
u205574338
1542599118
Python
Python3
py
Accepted
20
5976
194
n=int(input()) lst=list(map(int,input().split())) for i in range(n): x=lst[i] for j in range(i)[::-1]: if lst[j]<x:break lst[j+1]=lst[j] lst[j]=x print(*lst)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,699
s810955077
p02255
u150984829
1542552818
Python
Python3
py
Accepted
20
5976
119
N = int(input()) A = list(map(int, input().split())) for i in range(1, N + 1): A[:i] = sorted(A[:i]) print(*A)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,700
s652527013
p02255
u221424603
1542364469
Python
Python3
py
Accepted
30
5980
350
N=int(input()) A=list(map(int,input().split())) def hyouji(A): for z in range(len(A)): if z==0: print(A[z],end="") else: print(" "+str(A[z]),end="") print() hyouji(A) for i in range(1,N): v=A[i] j=i-1 while j>=0 and A[j]>v: A[j+1]=A[j] j=j-1...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,701
s692054520
p02255
u165578704
1542340427
Python
Python3
py
Accepted
20
5600
256
# -*- coding: utf-8 -*- N = int(input()) aN = list(map(str, input().split())) for i in range(N): tmp = aN[i] j = i - 1 while j >= 0 and int(aN[j]) > int(tmp): aN[j+1] = aN[j] j -= 1 aN[j+1] = tmp print(' '.join(aN))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,702
s732435583
p02255
u477100751
1542076485
Python
Python3
py
Accepted
20
5984
198
N = int(input()) *A, = list(map(int, input().split())) for i in range(N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print(*A)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,703
s496828270
p02255
u689047545
1542008886
Python
Python3
py
Accepted
30
5984
608
def insertionSort(a, n): for i in range(n): if i != n-1: print(a[i], end=" ") else: print(a[i], end="") print("") for i in range(1, n): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j+1] = a[j] j -= 1 a[j+1] = ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,704
s104513254
p02255
u978863922
1541942740
Python
Python3
py
Accepted
20
5596
341
#Insertion Sort #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A&lang=jp n = int(input()) l = list(map(int,input().split())) print (' '.join(map(str,l))) for i in range(1,n): v = l[i] j = i -1 while (j>=0 and l[j]>v ): l[j+1] = l[j] j -= 1 l[j+1] = v print (' ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,705
s083231233
p02255
u689181927
1541922646
Python
Python3
py
Accepted
20
5604
435
def insertion_sort(n, nums): print(' '.join(map(str,nums))) for i in range(1, n): v = nums[i] j = i -1 while j>=0 and v < nums[j]: nums[j+1] = nums[j] j-=1 nums[j+1] = v print(' '.join(map(str,nums))) def main(): n = int(input()) line = i...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,706
s200049087
p02255
u337252135
1541908000
Python
Python3
py
Accepted
20
5604
281
n=int(input()) A=[int(i) for i in input().split()] def show(): maplist=map(str, A) maplist=' '.join(maplist) print(maplist) show() for i in range(1,n): key=A[i] j=i-1 while j>=0 and A[j]>key: A[j+1]=A[j] j-=1 A[j+1]=key show()
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,707
s131587192
p02255
u532358959
1541862159
Python
Python3
py
Accepted
20
5592
238
n=int(input()) l=list(map(int,input().split())) print(" ".join(map(str,l))) for i in range(1,n): v = l[i] j = i - 1 while j >= 0 and l[j] > v: l[j+1] = l[j] j-=1 l[j+1] = v print(" ".join(map(str,l)))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,708
s270165960
p02255
u554503378
1541759614
Python
Python3
py
Accepted
20
5600
408
def insertion_sort(num_list): print(' '.join(num_list)) for i in range(1,len(num_list)): popped_num = num_list[i] j = i-1 while j >= 0 and int(num_list[j]) > int(popped_num): num_list[j+1] = num_list[j] j -=1 num_list[j+1] = popped_num print(' '.j...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,709
s007361971
p02255
u534994318
1541557287
Python
Python3
py
Accepted
20
5600
254
n = int(input()) array = list(map(int,input().split(" "))) for i in range(0, n): v = array[i] j = i - 1 while j >= 0 and array[j] > v: array[j+1] = array[j] j -= 1 array[j+1] = v print(" ".join(list(map(str, array))))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,710
s938179399
p02255
u717526540
1541490646
Python
Python3
py
Accepted
30
5984
360
n = int(input()) nlist = list(map(int, input().split())) ans = nlist.copy for i in range(n): v = nlist[i] j = i - 1 while j >= 0 and nlist[j] > v: nlist[j+1] = nlist[j] j -= 1 nlist[j+1] = v for j in range(n): if j == n-1: print(nlist[j]) else: ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,711
s416786097
p02255
u254642509
1541327080
Python
Python3
py
Accepted
20
5604
577
import sys def main(): inputslen = int(sys.stdin.readline().rstrip()) inputs= sys.stdin.readline() sortvalue = [int(i) for i in inputs.split()] for i in range(1, inputslen): printvalue = map(str, sortvalue) print(' '.join(printvalue)) compvalue = sortvalue[i] j = i - 1...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,712
s434978745
p02255
u635209856
1540027525
Python
Python3
py
Accepted
30
5976
360
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()) nums=list(map(int,input().split())) show(nums) for i in range(1,n): v=nums[i] j=i-1 while(j>=0 and nums[j]>v): nums[j+1]=nums[j] ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,713
s590472351
p02255
u446942899
1539589659
Python
Python3
py
Accepted
30
5980
440
N= int(input()) nums= list(map(int,input().split(" "))) for x in range(N): if(x!=N-1): print(nums[x],end=" ") else: print(nums[x]) for i in range(1,N): a= nums[i] j=i-1 while nums[j]>a and j>=0: nums[j+1]=nums[j] j-=1 nums[j+1]=a for x in range...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,714
s580273242
p02255
u885258297
1539523925
Python
Python3
py
Accepted
20
5600
260
N = int(input()) A = list(map(int, input().split())) print(" ".join(list(map(str, A)))) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v print(" ".join(list(map(str, A))))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,715
s254523250
p02255
u023863700
1539427257
Python
Python3
py
Accepted
20
5600
207
n=int(input()) a=list(map(int,input().split())) print(' '.join(list(map(str,a)))) for i in range(1,n): v=a[i] j=i-1 while j>=0 and a[j]>v: a[j+1]=a[j] a[j]=v j-=1 print(' '.join(list(map(str,a))))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,716
s523162410
p02255
u749884951
1539340561
Python
Python3
py
Accepted
20
5596
257
n = int(input()) A = list(map(int, input().split())) for i in range(1, n): print(' '.join(map(str, A))) key = A[i] j = i - 1 while j >= 0 and A[j] > key: A[j+1] = A[j] j = j - 1 A[j+1] = key print(' '.join(map(str, A)))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,717
s357838897
p02255
u932482488
1539189088
Python
Python3
py
Accepted
20
5600
322
N = int(input()) lst = list(map(int, input().split())) def printInt(L): print(" ".join(map(str, L))) for i in range(N): j = 0 while j < i: if lst[j] > lst[i]: break j += 1 tmp = lst[i] for x in range(i, j, -1): lst[x] = lst[x - 1] lst[j] = tmp printInt(lst...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,718
s673160701
p02255
u724084921
1539071362
Python
Python3
py
Accepted
20
5596
239
n=int(input()) a=list(map(int,input().split())) print(" ".join(map(str,a))) for i in range(1,n): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j+1] = a[j] j -= 1 a[j+1] = v print(" ".join(map(str,a)))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,719
s017272438
p02255
u726330006
1538913990
Python
Python3
py
Accepted
20
5604
272
n=int(input()) l=list(map(int,input().split())) print(" ".join(list(map(str,l)))) for i in range(1,n): x=l[i] for j in range(0,i)[::-1]: if(l[j] <= x): j+=1 break del l[i] l.insert(j,x) print(" ".join(list(map(str,l))))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,720
s151549711
p02255
u991280255
1538824243
Python
Python3
py
Accepted
40
6316
411
N = int(input()) A = list(map(int, input().split())) for k in range(N): print(A[k], end='') if k < N-1: print(' ', end='') print('') for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v for k in range(N): ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,721
s143035282
p02255
u498066648
1538792769
Python
Python3
py
Accepted
30
5980
378
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())) for i in range(0, len(r)): v = r[i] j = i-1 while (j >= 0) & (r[j] > v): r[j+1] = r[j] ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,722
s435763229
p02255
u924810243
1538632709
Python
Python
py
Accepted
10
4652
290
N = input() A = map(int,raw_input().split()) for i in range(N-1): print A[i], print A[-1] for i in range(1,N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v for i in range(N-1): print A[i], print A[-1]
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,723
s231809948
p02255
u820831349
1538228558
Python
Python3
py
Accepted
20
5600
374
def insertionSort(a: list, n: int): for i in range(1, n): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j+1] = a[j] j -= 1 a[j+1] = v a_str = map(str, a) print(" ".join(a_str)) n = int(input()) a = list(map(int, input().split())) a_str = map...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,724
s836582259
p02255
u760378812
1538058864
Python
Python3
py
Accepted
30
5604
412
n = int(input()) list_n = list((map(int, input().split()))) def insertionSort(list_a, n): for i in range(1,n): v = list_a[i] j = i - 1 while j >= 0 and list_a[j] > v: list_a[j+1] = list_a[j] j -= 1 list_a[j+1] = v print(" ".join([str(number) for number...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,725
s084559954
p02255
u800534567
1538025472
Python
Python3
py
Accepted
20
5608
345
def InsertionSort(A): print(' '.join(map(str, A))) for i in range(1,len(A)): key = A[i] j = i - 1 while j >= 0 and A[j] > key: A[j+1] = A[j] j-=1 A[j+1] = key print(' '.join(map(str, A))) return A input() a=[i for i in map(int, input().sp...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,726
s157611162
p02255
u901678083
1537948633
Python
Python3
py
Accepted
20
5604
226
def insertionSort(a,n): for i in range(n): v=a[i] j=i - 1 while j>=0 and a[j]>v: a[j+1]=a[j] j=j-1 a[j+1]=v print(' '.join(map(str,a))) n = int(input()) a = list(map(int,input().split())) insertionSort(a,n)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,727
s407253262
p02255
u415714413
1537513296
Python
Python3
py
Accepted
20
5604
309
def insertion(A,N): for i in range(1,N): print(" ".join([str(k) for k in A])) v=A[i] j=i-1 while j>=0 and A[j]>v: A[j+1]=A[j] j-=1 A[j+1]=v n=int(input()) A=list(map(int,input().split())) insertion(A,n) print(" ".join([str(k) for k in A]))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,728
s796757782
p02255
u428631405
1537110479
Python
Python3
py
Accepted
20
5600
302
# -*- coding: utf-8 -*- n = int(input()) nums = list(map(int, input().split())) for i in range(1, n): print(" ".join(map(str, nums))) v = nums[i] j = i - 1 while j >= 0 and nums[j] > v: nums[j + 1] = nums[j] j -= 1 nums[j + 1] = v print(" ".join(map(str, nums)))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,729
s540710798
p02255
u445032255
1537072304
Python
Python3
py
Accepted
20
5600
373
def print_list(A): print(" ".join(list(map(str, A)))) def main(): N = int(input()) A = list(map(int, input().split())) print_list(A) for i in range(1, N): store_v = A[i] j = i - 1 while j >= 0 and A[j] > store_v: A[j + 1] = A[j] j -= 1 ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,730
s294101169
p02255
u280118591
1536834915
Python
Python3
py
Accepted
20
5608
342
N = int(input()) A = [int(i) for i in input().split()] def insertionSort(arr): arr_len = len(arr) for i in range(arr_len): v = arr[i] j = i - 1 while j >= 0 and arr[j] > v : A[j +1] =A[j] j = j -1 arr[j+1] = v print(' '.join([str(x) for x in arr]...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,731
s761606443
p02255
u992449685
1536770914
Python
Python3
py
Accepted
30
5604
364
def Output(A): print(' '.join(list(map(str, A)))) def main(): N = int(input()) A = list(map(int, input().split())) for i in range(1, N): Output(A) v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v Output...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,732
s324861779
p02255
u959610989
1536569673
Python
Python3
py
Accepted
20
5984
195
#54 n=int(input()) *l,=list(map(int,input().split())) for i in range(n): temp=l[i] j=i-1 while j>=0 and l[j]>temp: l[j+1] = l[j] j-=1 l[j+1] = temp print(*l)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,733
s387596098
p02255
u401439950
1536469652
Python
Python3
py
Accepted
20
5980
216
n = int(input()) a = list(map(int, input().split())) print(*a) for i in range(1, n): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j + 1] = a[j] j = j - 1 a[j + 1] = v print(*a)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,734
s092602993
p02255
u643021750
1536374484
Python
Python3
py
Accepted
30
5976
416
n = int(input()) a = [int(_) for _ in input().split()] for i in range(n-1): print(a[i], end=" ") print(a[n-1]) for i in range(1, n): insert = a[i] # print('i', i) for j in range(i-1, -1, -1): # print('j', j) if a[j] > insert: a[j+1] = a[j] a[j] = insert e...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,735
s702658866
p02255
u993331153
1536137012
Python
Python3
py
Accepted
20
5604
456
#! python3 # insertion.py - 標準入出力を行う N = int(input()) l = input().split(' ') A = [int(i) for i in l] # print(A) def insertion(A, N): # N個の要素を含む0-オリジンの配列A for i in range(N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] j = j - 1 A[j+1] = v ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,736
s136765756
p02255
u094978706
1534392224
Python
Python3
py
Accepted
20
5596
262
N = int(input()) A = list(map(int, input().split() ) ) print( ' '.join(map(str, A)) ) for i in range(1, N): val = A[i] j = i - 1 while j >= 0 and A[j] > val : A[j+1] = A[j] j -= 1 A[j+1] = val print( ' '.join(map(str, A)) )
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,737
s784315092
p02255
u576786938
1534143511
Python
Python3
py
Accepted
20
5984
194
n = int(input()) a = list(map(int,input().split())) for i in range(n): v = a[i] j = i-1 while j>=0 and a[j]>v: a[j+1] = a[j] j -= 1 a[j+1] = v print(*a)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,738
s380880420
p02255
u145526353
1534082702
Python
Python3
py
Accepted
20
5616
788
# 挿入ソート トランプの時によく使う。 # # # # cnt = int(input()) numbers = list(map(int, input().split(' '))) def insertionsort(A, N): ''' :param A: N個の要素を含む0オリジンの配列 :param N: Aの要素数 :return: ''' print(' '.join(map(str, A))) for i in range(1, N): # ずらすために一時保存しておく変数 v = A[i] # ソート済み...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,739
s888392434
p02255
u907607057
1534080376
Python
Python3
py
Accepted
20
5604
508
def main(): input() sequence = list(map(int, input().split())) inserted = False for i in range(len(sequence)): n = sequence.pop(i) for j in sequence[:i]: if n <= j: sequence.insert(sequence.index(j), n) inserted = True break ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,740
s950332773
p02255
u313089641
1534061619
Python
Python3
py
Accepted
20
5596
242
n = int(input()) cards = list(map(int, input().split())) for i in range(n): v = cards[i] j = i-1 while j >= 0 and cards[j] > v: cards[j+1] = cards[j] j -= 1 cards[j+1] = v print(' '.join(map(str, cards)))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,741
s773276180
p02255
u404682284
1533793889
Python
Python3
py
Accepted
20
5612
274
n = int(input()) A = [int(i) for i in input().split()] print(' '.join([str(i) for i in A])) for i in range(1, n): key = A[i] j = i - 1 while j>=0 and A[j] > key: A[j+1] = A[j] j -= 1 A[j+1] = key print(' '.join([str(i) for i in A]))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,742
s348635945
p02255
u849721539
1533735638
Python
Python3
py
Accepted
20
5592
298
N=int(input()) S=list(map(str,input().split())) print(" ".join(S).rstrip()) for i in range(1,len(S)): for j in range(i): if int(S[j])>=int(S[i]): S.insert(j,S[i]) del S[i+1] else: pass print(" ".join(S).rstrip())
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,743
s924778365
p02255
u952951927
1533734668
Python
Python3
py
Accepted
40
6316
446
def pr(A): N = len(A); for i in range(N): if i : print (" ", end = ""); print (A[i], end = "") print ("") def insertionSort(A): pr(A) N = len(A) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j+1] = A[j] ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,744
s421122059
p02255
u024203289
1533604918
Python
Python3
py
Accepted
30
5600
358
N = int(input()) A = list(map(int, input().split())) def output_ary(): s = '' for x in A: s = s + str(x) + ' ' print(s.rstrip()) output_ary() i = 1 while i < N: V = A[i] j = i - 1 while j >= 0 and A[j] > V: A[j + 1] = A[j] j -= 1 A[j + ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,745
s498584949
p02255
u056253438
1533436283
Python
Python3
py
Accepted
20
5596
355
def insert_sort(A): array = A[:] for i in range(1, len(array)): print(' '.join(array)) v = array[i] j = i - 1 while j >= 0 and int(array[j]) > int(v): array[j + 1] = array[j] j -= 1 array[j + 1] = v return array _, A = input(), input().split...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,746
s759782586
p02255
u003929306
1533352417
Python
Python3
py
Accepted
20
5592
320
N = int(input()) S = list(map(int, input().split())) j = 0 for i in range(N): key = S[i] j = i - 1 while j>=0 and S[j] > key: S[j+1] = S[j] j-=1 S[j+1] = key res = "" for i in range(N): res += str(S[i]) if i < N-1: res += " " print(res)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,747
s527020420
p02255
u252054808
1533300795
Python
Python3
py
Accepted
20
5604
336
N = int(input()) A = list(map(int, input().split())) str_A = [str(a) for a in A] result = ' '.join(str_A) print(result) for i in range(1, N, 1): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j+1] = v str_A = [str(a) for a in A] result = ' '.join(str_A) ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,748
s718046396
p02255
u751769081
1533177181
Python
Python3
py
Accepted
20
5980
286
def insertionSort(N): for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and v < A[j]: A[j + 1] = A[j] j -= 1 A[j + 1] = v print(*A) N = int(input()) A = list(map(int, input().split())) print(*A) insertionSort(N)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,749
s635214821
p02255
u780025254
1533014206
Python
Python3
py
Accepted
20
5980
284
input() x = list(map(int, input().split())) def insertion_sort(a): print(*a) for i in range(1, len(a)): v = a[i] j = i - 1 while j >= 0 and a[j] > v: a[j+1] = a[j] j -= 1 a[j+1] = v print(*a) insertion_sort(x)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,750
s381557820
p02255
u063056051
1532525881
Python
Python3
py
Accepted
20
5608
235
def I_S(a,n): print(' '.join(map(str,a))) for i in range(1,n): v=a[i] j=i-1 while j>=0 and a[j]>v: a[j+1]=a[j] j-=1 a[j+1]=v print(' '.join(map(str,a))) n=int(input()) a=[int(x) for x in input().split()] I_S(a,n)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,751
s850960057
p02255
u248424983
1532308874
Python
Python3
py
Accepted
20
5592
251
N = int(input()) A = list(map(int, input().split())) for i in range(1, N): v = A[i] j = i - 1 print(' '.join(map(str, A))) while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v print(' '.join(map(str, A)))
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,752
s095384930
p02255
u891568341
1532252801
Python
Python3
py
Accepted
40
6316
564
def inserts(N): k = 1 for n in N: print(n, end='') if k < len(N): print(' ', end='') k += 1 print('') for i in range(1,len(N)): v = N[i] j = i - 1 while j >= 0 and N[j] > v: N[j + 1] = N[j] j -= 1 N[j + 1] = v ...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,753
s416533263
p02255
u245823788
1532169571
Python
Python3
py
Accepted
20
5604
278
n = int(input()) a = list(map(int, input().split())) def insertionSort(): for i in range(1, n): v = a[i] j = i-1 while j>=0 and a[j]>v: a[j+1] = a[j] j -= 1 a[j+1] = v print(" ".join(map(str, a))) print(" ".join(map(str, a))) insertionSort()
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,754
s935702260
p02255
u171377572
1528776074
Python
Python3
py
Accepted
30
5988
229
N = int(input()) A = list(map(int, input().split())) for i in range(N): p = i - 1 while p >= 0 and A[p] > A[p + 1]: A[p], A[p + 1] = A[p + 1], A[p] p -= 1 for j in range(N): print(A[j], end = " \n"[j + 1 == N])
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,755
s890368726
p02255
u853158149
1521797545
Python
Python3
py
Accepted
50
5976
297
n = int(input()) s = input() print(s) s = s.split(" ") for i in range(n): s[i] = int(s[i]) for i in range(1,n): v = s[i] j = i-1 while j >= 0 and s[j] > v: s[j+1] = s[j] j -= 1 s[j+1] = v for k in range(n-1): print(s[k],end = " ") print(s[n-1])
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,756
s120085772
p02255
u079141094
1466644267
Python
Python3
py
Accepted
30
7712
283
def insertion_sort(A,N): prin(A) for i in range(1,N): v = A[i] j = i-1 while j >= 0 and A[j] > v: A[j+1] = A[j] j -= 1 A[j+1] = v prin(A) def prin(A): print(' '.join(list(map(str, A)))) N = int(input()) A = [int(i) for i in input().split(' ')] insertion_sort(A,N)
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,757
s793052206
p02255
u717727327
1421067407
Python
Python
py
Accepted
20
4224
400
def insertion_sort(A): print " ".join(map(str, A)) for i in range(1, len(A)): key = A[i] # insert A[i] into the sorted sequience A[0,...,j-1] j = i - 1 while j >= 0 and A[j] > key: A[j+1] = A[j] j -= 1 A[j+1] = key print " ".join(map(str, A...
p02255
<H1>Insertion Sort</H1> <p> Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: </p> <pre> for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >...
6 5 2 4 6 1 3
5 2 4 6 1 3 2 5 4 6 1 3 2 4 5 6 1 3 2 4 5 6 1 3 1 2 4 5 6 3 1 2 3 4 5 6
31,758
s142147646
p02256
u986487972
1530790052
Python
Python3
py
Accepted
20
5600
219
c,d = list(map(int,input().split())) if d>c: a = d b = c else: a = c b = d def gcd(x,y): if y == 0: return x else: r = x%y return gcd(y,r) print(gcd(a,b))
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,759
s129318344
p02256
u806005289
1530797551
Python
Python3
py
Accepted
20
5608
1,155
twoNumbers=list(map(int,input().split())) x=twoNumbers[0] y=twoNumbers[1] devidedBy=[] syou=[] if x>=y: for number in range(1, y+1): if y%number==0: if number>y//number: break else: if not number in devidedBy: devidedBy.append(numbe...
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,760
s723912542
p02256
u938878704
1530931852
Python
Python3
py
Accepted
20
5600
297
X, Y = map(int, input().split()) def gcd(_x, _y) : x = min(_x, _y) y = max(_x, _y) if x == 0 or y == 0 : return 0 if x == y : return X elif y % x == 0 : return min(x, y) elif y % x != 0 : return gcd(y % x, x) print(gcd(X, Y))
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,761
s223765747
p02256
u313089641
1531237341
Python
Python3
py
Accepted
20
5600
233
a, b = map(int, input().split()) def gcd(a, b): if a == b: return a big = max(a, b) small = min(a, b) while not big % small == 0: big, small = small, big%small return small print(gcd(a, b))
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,762
s171532676
p02256
u313089641
1531237566
Python
Python3
py
Accepted
20
5600
201
a, b = map(int, input().split()) def gcd(a, b): big = max(a, b) small = min(a, b) while not big % small == 0: big, small = small, big%small return small print(gcd(a, b))
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,763
s740589774
p02256
u888550928
1531478900
Python
Python3
py
Accepted
20
5596
221
x, y = map(int, input().split()) while True: if x > y: x = x % y if x == 0: print(y) break else: y = y % x if y == 0: print(x) break
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,764
s217026025
p02256
u539753516
1531541573
Python
Python3
py
Accepted
20
5652
62
import math a,b=map(int,input().split()) print(math.gcd(a,b))
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,765
s814622437
p02256
u400765446
1531660887
Python
Python3
py
Accepted
20
5600
295
def main(): a, b = tuple(map(int,input().split())) if a < b: (a, b) = (b, a) # a > b となるように並べ替え print(gcd(a, b)) def gcd(x, y): if y == 0: return x else: return gcd(y, x%y) if __name__ == '__main__': main()
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,766
s257810425
p02256
u400765446
1531661006
Python
Python3
py
Accepted
20
5600
257
def main(): a, b = tuple(map(int,input().split())) print(gcd(a, b)) def gcd(x, y): # x > y となるように並べ替え if x < y: (x, y) = (y, x) return x if y == 0 else gcd(y, x%y) if __name__ == '__main__': main()
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,767
s907223362
p02256
u715990255
1531834768
Python
Python3
py
Accepted
20
5600
191
nums = sorted(list(map(int, input().split())), reverse=True) def gcd(mx, mi): if mi == 0: return mx amari = mx % mi return gcd(mi, amari) print(gcd(nums[0], nums[1]))
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,768
s978164152
p02256
u302561071
1532008321
Python
Python
py
Accepted
10
4648
224
import sys input_list = map(int, raw_input().split()) x = input_list[0] y = input_list[1] if x < y: tmp = x x = y y = tmp elif x == y: print(x) sys.exit(0) r = 0 while y != 0: r = x % y x = y y = r print(x)
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,769
s464205146
p02256
u123669391
1532012047
Python
Python3
py
Accepted
20
5648
778
a, b = map(int, input().split()) c = [] if a > b: a, b = b, a if b%a == 0: print(a) else: while True: for i in range(a): x = i + 2 #print(a, x) if a%x == 0: if b%x == 0: c.append(x) a = a//x ...
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,770
s602064813
p02256
u123669391
1532012078
Python
Python3
py
Accepted
20
5648
638
a, b = map(int, input().split()) c = [] if a > b: a, b = b, a if b%a == 0: print(a) else: while True: for i in range(a): x = i + 2 if a%x == 0: if b%x == 0: c.append(x) a = a//x b = b//x ...
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,771
s897208738
p02256
u525366883
1535088858
Python
Python
py
Accepted
10
4628
117
def gcd(x,y): while y: x, y = y, x % y return x a,b = map(int, raw_input().split()) print gcd(a, b)
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,772
s805894874
p02256
u751769081
1535344489
Python
Python3
py
Accepted
20
5600
123
def gcd(x, y): if y == 0: return print(x) return gcd(y, x % y) x, y = map(int, input().split()) gcd(x, y)
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,773
s501254041
p02256
u462873421
1535526606
Python
Python
py
Accepted
10
4636
158
def gcd(aa,bb): while bb!=0: r=bb bb=aa%bb aa=r return aa a,b=map(int,raw_input().strip().split()) #print a,b print gcd(a,b)
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,774
s491061064
p02256
u665238221
1535535923
Python
Python3
py
Accepted
20
5596
143
def gcd(a, b): if a < b: a, b = b, a while b != 0: a, b = b, a % b return a print(gcd(*map(int, input().split())))
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,775
s751585244
p02256
u317583692
1535619545
Python
Python3
py
Accepted
20
5600
169
a,b = map(int,input().split()) def gcd(x,y): q = max(x,y) % min(x,y) if q == 0 : return [min(x,y),0] return gcd(min(x,y),q) print(max(gcd(a,b)))
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,776
s595993591
p02256
u554503378
1540275384
Python
Python3
py
Accepted
20
5608
325
def sort_two_nums_tuple(x,y): return max(x,y),min(x,y) def calculate_gcd(x,y): remain = float('inf') while remain != 0: remain = x % y x = y y = remain return x input_x,input_y = map(int,input().split()) x,y = sort_two_nums_tuple(input_x,input_y) ans = calculate_gcd(x,y) print(...
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,777
s448614204
p02256
u744506422
1540293615
Python
Python3
py
Accepted
20
5600
158
def gcd(x,y): a=max(x,y) b=min(x,y) if a%b==0: return b else: return gcd(a%b,b) A,B=map(int,input().split()) print(gcd(A,B))
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,778
s375327703
p02256
u901205536
1541081841
Python
Python3
py
Accepted
20
5668
303
import math def div(x, y): #x>y A = 1 for i in range(1, int(math.sqrt(x))+1): if x % i == 0 and y % i == 0: A = max(A, i) j = int(x/i) if x % j == 0 and y % j == 0: A = max(A, j) return A x, y = map(int, input().split(" ")) print(div(x,y))
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,779
s147069234
p02256
u209940149
1541148870
Python
Python3
py
Accepted
20
5604
201
def gcd(a, b): c = max([a, b]) d = min([a, b]) if c % d == 0: return d else: return gcd(d, c % d) nums = input().split() print(gcd(int(nums[0]), int(nums[1])))
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,780
s531104983
p02256
u874395007
1546398929
Python
Python3
py
Accepted
20
5600
103
x, y = map(int, input().split()) if x < y: x, y = y, x while y > 0: x, y = y, x % y print(x)
p02256
<H1>Greatest Common Divisor</H1> <p> Write a program which finds the greatest common divisor of two natural numbers <i>a</i> and <i>b</i> </p> <H2>Input</H2> <p> <i>a</i> and <i>b</i> are given in a line sparated by a single space. </p> <H2>Output</H2> <p> Output the greatest common divisor of <i>a</i> and <i>b</...
54 20
2
31,781