problem_id
stringlengths 6
6
| buggy_code
stringlengths 8
526k
| fixed_code
stringlengths 12
526k
| labels
listlengths 0
15
⌀ | buggy_submission_id
int64 1
1.54M
| fixed_submission_id
int64 2
1.54M
| user_id
stringlengths 10
10
| language
stringclasses 8
values |
|---|---|---|---|---|---|---|---|
p02257
|
n = gets.to_i
m = []
p_num = 0
n.times{
m += [gets.to_i]
}
for x in m
flag = 0
for y in 2..(x**0.5)+1
if x % y == 0
flag = 1
break
end
end
if flag == 0
p_num += 1
end
end
puts p_num
|
n = gets.to_i
m = []
p_num = 0
n.times{
m += [gets.to_i]
}
for x in m
flag = 0
for y in 2..(x**0.5)
if x % y == 0
flag = 1
break
end
end
if flag == 0
p_num += 1
end
end
puts p_num
|
[
"expression.operation.binary.remove"
] | 100,951
| 100,952
|
u547057305
|
ruby
|
p02259
|
class Array
def swap!(a, b)
self[a], self[b] = self[b], self[a]
self
end
end
def bubble_sort(array)
isSorted = false
count = 0
index = 0
until isSorted do
swaped = false
(array.length - 1).downto(index) do |comp_index|
break if comp_index.zero?
if array[comp_index] < array[comp_index - 1]
array.swap! index, (index - 1)
count += 1
swaped = true
end
end
isSorted = true unless swaped
index += 1
end
[array, count]
end
n = gets.to_i
array = gets.split(' ').map(&:to_i)
result_array, count = bubble_sort array
puts result_array.join ' '
puts count
|
class Array
def swap!(a, b)
self[a], self[b] = self[b], self[a]
self
end
end
def bubble_sort(array)
isSorted = false
count = 0
index = 0
until isSorted do
swaped = false
(array.length - 1).downto(index) do |comp_index|
break if comp_index.zero?
if array[comp_index] < array[comp_index - 1]
array.swap! comp_index, (comp_index - 1)
count += 1
swaped = true
end
end
isSorted = true unless swaped
index += 1
end
[array, count]
end
n = gets.to_i
array = gets.split(' ').map(&:to_i)
result_array, count = bubble_sort array
puts result_array.join ' '
puts count
|
[
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 103,510
| 103,511
|
u731989230
|
ruby
|
p02260
|
$swap = 0
def Swap(a, b)
$swap += 1
return b,a
end
gets
d = gets.chomp.split(" ").map &:to_i
d.length.times { |i|
min = i
(i..d.length).each_with_index { |j|
min = j if d[min] > d[j]
}
d[i],d[min] = Swap(d[i],d[min])
}
d.length.times { |i|
print " " unless i == 0
print "#{d[i]}"
}
print "\n#{$swap}\n"
|
$swap = 0
def Swap(a, b)
$swap += 1
return b,a
end
gets
d = gets.chomp.split(" ").map &:to_i
d.length.times { |i|
min = i
(i...d.length).each_with_index { |j|
min = j if d[min] > d[j]
}
d[i],d[min] = Swap(d[i],d[min]) if i != min
}
d.length.times { |i|
print " " unless i == 0
print "#{d[i]}"
}
print "\n#{$swap}\n"
|
[] | 104,143
| 104,144
|
u281257618
|
ruby
|
p02260
|
$swap = 0
def Swap(a, b)
$swap += 1
return b,a
end
gets
d = gets.chomp.split(" ").map &:to_i
d.length.times { |i|
min = i
(i...d.length).each_with_index { |j|
min = j if d[min] > d[j]
}
d[i],d[min] = Swap(d[i],d[min])
}
d.length.times { |i|
print " " unless i == 0
print "#{d[i]}"
}
print "\n#{$swap}\n"
|
$swap = 0
def Swap(a, b)
$swap += 1
return b,a
end
gets
d = gets.chomp.split(" ").map &:to_i
d.length.times { |i|
min = i
(i...d.length).each_with_index { |j|
min = j if d[min] > d[j]
}
d[i],d[min] = Swap(d[i],d[min]) if i != min
}
d.length.times { |i|
print " " unless i == 0
print "#{d[i]}"
}
print "\n#{$swap}\n"
|
[] | 104,145
| 104,144
|
u281257618
|
ruby
|
p02260
|
input = []
while (n = gets.to_i) != 0 do
input = gets.split.map(&:to_i)
end
n = input.size
count = 0
for i in 0..n-1 do
min_j = i
for j in i..n-1 do
min_j = j if input[j] < input[min_j]
end
break if input[min_j] == input[i]
tmp = input[min_j]
input[min_j] = input[i]
input[i] = tmp
count += 1
end
puts input*" "
puts count
|
# 選択ソート(最小のものを先頭に追加していくイメージ。)
input = []
while (n = gets.to_i) != 0 do
input = gets.split.map(&:to_i)
end
n = input.size
count = 0
for i in 0..n-1 do
min_j = i
for j in i..n-1 do
min_j = j if input[j] < input[min_j]
end
if input[min_j] != input[i]
tmp = input[min_j]
input[min_j] = input[i]
input[i] = tmp
count += 1
end
end
puts input*" "
puts count
|
[
"control_flow.break.remove",
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 104,150
| 104,151
|
u854817684
|
ruby
|
p02258
|
n = gets(chomp:true).to_i
# 最大利益を負の無限大に設定!!!
maxv = -Float::INFINITY
# 最小値を読み込み
minv = gets(chomp:true).to_i
(1..n).each do |price_idx|
# 比較する価格を読み込み
price = gets(chomp:true).to_i
# 最大利益が価格-最小値より小さい場合。最大利益を更新
maxv < price - minv && maxv = price - minv
# 最小値が価格より大きい場合、最小値を更新
minv > price && minv = price
end
puts maxv
|
n = gets(chomp:true).to_i
# 最大利益を負の無限大に設定!!!
maxv = -Float::INFINITY
# 最小値を読み込み
minv = gets(chomp:true).to_i
(1...n).each do
# 比較する価格を読み込み
price = gets(chomp:true).to_i
# 最大利益が価格-最小値より小さい場合。最大利益を更新
maxv < price - minv && maxv = price - minv
# 最小値が価格より大きい場合、最小値を更新
minv > price && minv = price
end
puts maxv
|
[] | 104,221
| 104,222
|
u958508535
|
ruby
|
p02258
|
n = gets.chomp.to_i
a = []
n.times do
a.push(gets.chomp.to_i)
end
max_gap = 0
low = a[0]
for i in 1..a.size-1
if a[i] - low > max_gap
max_gap = a[i] - low
elsif a[i] < low
low = a[i]
end
end
puts max_gap
|
n = gets.chomp.to_i
a = []
n.times do
a.push(gets.chomp.to_i)
end
max_gap = -Float::INFINITY
low = a[0]
for i in 1..a.size-1
if a[i] - low > max_gap
max_gap = a[i] - low
end
if a[i] < low
low = a[i]
end
end
puts max_gap
|
[
"assignment.value.change"
] | 104,225
| 104,226
|
u742797815
|
ruby
|
p02258
|
n = gets.chomp.to_i
a = []
n.times do
a.push(gets.chomp.to_i)
end
max_gap = -Float::INFINITY
low = a[0]
for i in 1..a.size-1
if a[i] - low > max_gap
max_gap = a[i] - low
elsif a[i] < low
low = a[i]
end
end
puts max_gap
|
n = gets.chomp.to_i
a = []
n.times do
a.push(gets.chomp.to_i)
end
max_gap = -Float::INFINITY
low = a[0]
for i in 1..a.size-1
if a[i] - low > max_gap
max_gap = a[i] - low
end
if a[i] < low
low = a[i]
end
end
puts max_gap
|
[] | 104,227
| 104,226
|
u742797815
|
ruby
|
p02258
|
_,m,*a=$<.map &:to_i
p a.map{|i|m=i if 0<s=i-m
s}.max
|
_,m,*a=$<.map &:to_i
p a.map{|i|m=i if 0>s=i-m
s}.max
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 104,228
| 104,229
|
u890794282
|
ruby
|
p02258
|
gets
n=2e9
m=0
$<.map{|c|i=c.to_i;m<i-n&&m=i-n;n>i&&n=i}
p m
|
gets
n=2e9
m=-n
$<.map{|c|i=c.to_i;m<i-n&&m=i-n;n>i&&n=i}
p m
|
[
"assignment.value.change",
"expression.operation.unary.add"
] | 104,232
| 104,233
|
u198069342
|
ruby
|
p02258
|
n = gets.to_i
ret = -1000000000
j = gets.to_i
min = j
max = j
for i in 2..n
j = gets.to_i
if min > j
ret = j - min if ret < j - min
min = j
max = j
end
if max < j
max = j
ret = max - min if ret < max - min
end
end
puts ret
|
n = gets.to_i
ret = -1000000000
j = gets.to_i
min = j
max = j
for i in 2..n
j = gets.to_i
if min >= j
ret = j - min if ret < j - min
min = j
max = j
end
if max < j
max = j
ret = max - min if ret < max - min
end
end
puts ret
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 104,237
| 104,238
|
u324171823
|
ruby
|
p02258
|
n = STDIN.gets.to_i
n1 = STDIN.gets.to_i
n2 = STDIN.gets.to_i
max = n1
min = n1
if n1 > n2 then
min = n2
diff = n2 - n1
max = n2
else
max = n2
diff = n2 - n1
end
(3..n).each { |i|
x = STDIN.gets.to_i
max = x if max.nil?
min = -x if min.nil?
if x > max then
diff = x - min if x - min > diff
max = x
elsif x < min then
diff = x - max if x - max > diff
min = x
max = x
end
}
puts diff
|
n = STDIN.gets.to_i
n1 = STDIN.gets.to_i
n2 = STDIN.gets.to_i
max = n1
min = n1
if n1 > n2 then
min = n2
diff = n2 - n1
max = n2
else
max = n2
diff = n2 - n1
end
(3..n).each { |i|
x = STDIN.gets.to_i
max = x if max.nil?
min = -x if min.nil?
if x > max then
diff = x - min if x - min > diff
max = x
elsif x <= min then
diff = x - max if x - max > diff
min = x
max = x
end
}
puts diff
|
[
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 104,244
| 104,245
|
u382730661
|
ruby
|
p02258
|
n = STDIN.gets.to_i
p n
max = -2000000000
min = STDIN.gets.to_i
(2..n).each { |i|
x = STDIN.gets.to_i
max = if max > x - min then max else x - min end
min = if x < min then x else min end
}
puts max
|
n = STDIN.gets.to_i
max = -2000000000
min = STDIN.gets.to_i
(2..n).each { |i|
x = STDIN.gets.to_i
max = if max > x - min then max else x - min end
min = if x < min then x else min end
}
puts max
|
[
"call.remove"
] | 104,251
| 104,252
|
u677710583
|
ruby
|
p02258
|
n = gets.to_i
rs = readlines.take(n).map(&:to_i)
_, max_profit = rs.drop(0).reduce([rs[0], -(10 ** n)]) do |(min_r, max_profit), r|
max_profit = [max_profit, r - min_r].max
min_r = r if r < min_r
[min_r, max_profit]
end
puts max_profit
|
n = gets.to_i
rs = readlines.take(n).map(&:to_i)
_, max_profit = rs.drop(1).reduce([rs[0], -(10 ** 9)]) do |(min_r, max_profit), r|
max_profit = [max_profit, r - min_r].max
min_r = r if r < min_r
[min_r, max_profit]
end
puts max_profit
|
[
"literal.number.integer.change",
"assignment.value.change",
"call.arguments.change",
"identifier.replace.remove",
"literal.replace.add",
"expression.operation.binary.change"
] | 104,262
| 104,263
|
u694668170
|
ruby
|
p02258
|
n = gets.to_i
r = Array.new
r0 = gets.to_i
r1 = gets.to_i
max_r = - r0
min_v = r0 < r1 ? r0 : r1
(n-2).times do
r = gets.to_i
current = r - min_v
max_r = current if current > max_r
min_v = r if r < min_v
end
puts max_r
|
n = gets.to_i
r = Array.new
r0 = gets.to_i
r1 = gets.to_i
max_r = r1 - r0
min_v = r0 < r1 ? r0 : r1
(n-2).times do
r = gets.to_i
current = r - min_v
max_r = current if current > max_r
min_v = r if r < min_v
end
puts max_r
|
[] | 104,268
| 104,269
|
u107950945
|
ruby
|
p02258
|
n = gets.to_i
min = last = gets.to_i
profits = []
(n-2).times{
current = gets.to_i
profits<<(current-min) if (profits.bsearch{|i| i >= 0} == nil) || (current > last)
min = current if (current < min)
last = current
}
puts profits.max
|
n = gets.to_i
min = last = gets.to_i
profits = []
(n-1).times{
current = gets.to_i
profits<<(current-min) if (profits.bsearch{|i| i >= 0} == nil) || (current > last)
min = current if (current < min)
last = current
}
puts profits.max
|
[
"literal.number.integer.change",
"expression.operation.binary.change"
] | 104,274
| 104,275
|
u213421924
|
ruby
|
p02258
|
n = gets.to_i
a = gets.to_i
b = gets.to_i
can = b-a
if n==2 then
puts can
else
if a>b then
left = b
end
m = n-2
m.times{
right = gets.to_i
d = right - left
if d>can then
can = d
end
if right< left then
left = right
end
}
puts can
end
|
n = gets.to_i
a = gets.to_i
b = gets.to_i
can = b-a
if n==2 then
puts can
else
if a>b then
left = b
else
left = a
end
m = n-2
m.times{
right = gets.to_i
d = right - left
if d>can then
can = d
end
if right < left then
left = right
end
}
puts can
end
|
[
"assignment.add"
] | 104,290
| 104,291
|
u350127362
|
ruby
|
p02258
|
n = gets.to_i
a = gets.to_i
b = gets.to_i
can = b-a
if n==2 then
puts can
else
if a>b then
left = b
end
m = n-2
m.times{
right = gets.to_i
d = right - left
if d>can then
can = d
end
if right < left then
left = right
end
}
puts can
end
|
n = gets.to_i
a = gets.to_i
b = gets.to_i
can = b-a
if n==2 then
puts can
else
if a>b then
left = b
else
left = a
end
m = n-2
m.times{
right = gets.to_i
d = right - left
if d>can then
can = d
end
if right < left then
left = right
end
}
puts can
end
|
[
"assignment.add"
] | 104,292
| 104,291
|
u350127362
|
ruby
|
p02258
|
arr = []
n = gets.to_i
n.times do
input = gets.to_i
arr << input
end
max = -2000000000000000
minv = arr[0]
arr.length.times do |i|
i += 1
max = arr[i] - minv if(arr[i] - minv > max)
minv = arr[i] if(arr[i] < minv)
end
p max
|
arr = []
n = gets.to_i
n.times do
input = gets.to_i
arr << input
end
max = -2000000000000000
minv = arr[0]
(arr.length - 1).times do |i|
i += 1
max = arr[i] - minv if(arr[i] - minv > max)
minv = arr[i] if(arr[i] < minv)
end
p max
|
[] | 104,293
| 104,294
|
u352940122
|
ruby
|
p02258
|
arr = []
n = gets.to_i
n.times do
input = gets.to_i
arr << input
end
max = -2000000000000000
minv = arr[0]
(arr.length - 1).times do |i|
i += 1
max = arr[i] - minv if(arr[0] - minv > max)
minv = arr[i] if(arr[i] < minv)
end
p max
|
arr = []
n = gets.to_i
n.times do
input = gets.to_i
arr << input
end
max = -2000000000000000
minv = arr[0]
(arr.length - 1).times do |i|
i += 1
max = arr[i] - minv if(arr[i] - minv > max)
minv = arr[i] if(arr[i] < minv)
end
p max
|
[
"identifier.replace.add",
"literal.replace.remove",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 104,295
| 104,294
|
u352940122
|
ruby
|
p02263
|
while ary = gets
ary.chomp
stack = []
ary = str.split(" ")
while ary.size>0
a = ary.shift
if a == "+"
x = stack.shift.to_i + stack.shift.to_i
elsif a == "-"
x = -stack.shift.to_i + stack.shift.to_i
elsif a == "*"
x = stack.shift.to_i * stack.shift.to_i
else
x = a
end
stack.unshift(x)
end
puts stack[0]
end
|
while ary = gets
ary.chomp
stack = []
ary = ary.split(" ")
while ary.size>0
a = ary.shift
if a == "+"
x = stack.shift.to_i + stack.shift.to_i
elsif a == "-"
x = -stack.shift.to_i + stack.shift.to_i
elsif a == "*"
x = stack.shift.to_i * stack.shift.to_i
else
x = a
end
stack.unshift(x)
end
puts stack[0]
end
|
[
"assignment.value.change",
"identifier.change"
] | 107,557
| 107,558
|
u535246834
|
ruby
|
p02263
|
MODE = "stdio"
#require 'matrix'
#include Math
line = Array.new
if(defined? MODE)
line = STDIN.read.split("\n")
else
tmp = '1 2 +'.split("\n")
tmp.each{|s|
line << s.strip
}
end
arr = line[0].split(" ")
stack = []
arr.each do |i|
case i
when "+"
stack.push(stack.pop+stack.pop)
when "-"
stack.push(stack.pop-stack.pop)
when "*"
stack.push(stack.pop*stack.pop)
else
stack.push(i.to_i)
end
end
puts stack.pop
|
MODE = "stdio"
#require 'matrix'
#include Math
line = Array.new
if(defined? MODE)
line = STDIN.read.split("\n")
else
tmp = '1 1 +'.split("\n")
tmp.each{|s|
line << s.strip
}
end
arr = line[0].split(" ")
stack = []
arr.each do |i|
case i
when "+"
stack.push(stack.pop+stack.pop)
when "-"
stack.push(-stack.pop+stack.pop)
when "*"
stack.push(stack.pop*stack.pop)
else
stack.push(i.to_i)
end
# p stack
end
puts stack.pop
|
[
"literal.string.change",
"assignment.value.change",
"expression.operation.unary.add",
"call.arguments.change",
"misc.opposites",
"expression.operator.arithmetic.change",
"expression.operation.binary.change"
] | 107,563
| 107,564
|
u876514616
|
ruby
|
p02261
|
def bubble_sort(a)
arr = a.dup
n = arr.length
for i in 0..n - 1
j = n - 1
while j > i
if arr[j-1][1] > arr[j][1]
arr[j-1],arr[j] = arr[j],arr[j-1]
end
j -= 1
end
end
arr
end
def selection_sort(arr)
a = arr.dup
for i in 0..(a.length - 1)
min = i
for j in i ..(a.length - 1)
if a[j][1] < a[min][1]
min = j
end
end
a[i], a[min] = a[min], a[i]
end
a
end
gets
x = gets.split.map { |v| [v[0], v[1].to_i] }
b = bubble_sort(x)
s = selection_sort(x)
puts b.map(&:join).join(' ')
puts 'Stable'
puts s.map(&:join).join(' ')
puts b == s ? 'Stable' : 'Not Stable'
|
def bubble_sort(a)
arr = a.dup
n = arr.length
for i in 0..n - 1
j = n - 1
while j > i
if arr[j-1][1] > arr[j][1]
arr[j-1],arr[j] = arr[j],arr[j-1]
end
j -= 1
end
end
arr
end
def selection_sort(arr)
a = arr.dup
for i in 0..(a.length - 1)
min = i
for j in i ..(a.length - 1)
if a[j][1] < a[min][1]
min = j
end
end
a[i], a[min] = a[min], a[i]
end
a
end
gets
x = gets.split.map { |v| [v[0], v[1].to_i] }
b = bubble_sort(x)
s = selection_sort(x)
puts b.map(&:join).join(' ')
puts 'Stable'
puts s.map(&:join).join(' ')
puts b == s ? 'Stable' : 'Not stable'
|
[
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 107,997
| 107,998
|
u739433776
|
ruby
|
p02261
|
# ALDS1_2_C Stable Sort
n = gets.chomp.to_i
a = gets.chomp.split(" ")
def bubbleSort(c, n)
a = c.dup
(0..n-1).each do |i|
(n-1).downto(i) do |j|
if a[j][1].to_i < a[j-1][1].to_i
a[j], a[j-1] = a[j-1], a[j]
end
end
end
return a
end
def selectionSort(c, n)
a = c.dup
(0..n-1).each do |i|
minj = i
(i..n-1).each do |j|
if a[j][1].to_i < a[minj][1].to_i then
minj = j
end
end
a[i], a[minj] = a[minj], a[i]
end
return a
end
bubble = bubbleSort(a, n)
selection = selectionSort(a, n)
puts bubble.join(" ")
puts "Stable"
puts selection.join(" ")
if bubble == selection then
puts "Stable"
else
puts "Unstable"
end
|
# ALDS1_2_C Stable Sort
n = gets.chomp.to_i
a = gets.chomp.split(" ")
def bubbleSort(c, n)
a = c.dup
(0..n-1).each do |i|
(n-1).downto(i+1) do |j|
if a[j][1].to_i < a[j-1][1].to_i
a[j], a[j-1] = a[j-1], a[j]
end
end
end
return a
end
def selectionSort(c, n)
a = c.dup
(0..n-1).each do |i|
minj = i
(i..n-1).each do |j|
if a[j][1].to_i < a[minj][1].to_i then
minj = j
end
end
a[i], a[minj] = a[minj], a[i]
end
return a
end
bubble = bubbleSort(a, n)
selection = selectionSort(a, n)
puts bubble.join(" ")
puts "Stable"
puts selection.join(" ")
if bubble == selection then
puts "Stable"
else
puts "Not stable"
end
|
[
"literal.string.change",
"call.arguments.change"
] | 107,999
| 108,000
|
u247976584
|
ruby
|
p02261
|
# ALDS1_2_C Stable Sort
n = gets.chomp.to_i
a = gets.chomp.split(" ")
def bubbleSort(c, n)
a = c.dup
(0..n-1).each do |i|
(n-1).downto(i) do |j|
if a[j][1].to_i < a[j-1][1].to_i
a[j], a[j-1] = a[j-1], a[j]
end
end
end
return a
end
def selectionSort(c, n)
a = c.dup
(0..n-1).each do |i|
minj = i
(i..n-1).each do |j|
if a[j][1].to_i < a[minj][1].to_i then
minj = j
end
end
a[i], a[minj] = a[minj], a[i]
end
return a
end
bubble = bubbleSort(a, n)
selection = selectionSort(a, n)
puts bubble.join(" ")
puts "Stable"
puts selection.join(" ")
if bubble == selection then
puts "Stable"
else
puts "Not Stable"
end
|
# ALDS1_2_C Stable Sort
n = gets.chomp.to_i
a = gets.chomp.split(" ")
def bubbleSort(c, n)
a = c.dup
(0..n-1).each do |i|
(n-1).downto(i+1) do |j|
if a[j][1].to_i < a[j-1][1].to_i
a[j], a[j-1] = a[j-1], a[j]
end
end
end
return a
end
def selectionSort(c, n)
a = c.dup
(0..n-1).each do |i|
minj = i
(i..n-1).each do |j|
if a[j][1].to_i < a[minj][1].to_i then
minj = j
end
end
a[i], a[minj] = a[minj], a[i]
end
return a
end
bubble = bubbleSort(a, n)
selection = selectionSort(a, n)
puts bubble.join(" ")
puts "Stable"
puts selection.join(" ")
if bubble == selection then
puts "Stable"
else
puts "Not stable"
end
|
[
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 108,001
| 108,000
|
u247976584
|
ruby
|
p02261
|
# ALDS1_2_C Stable Sort
n = gets.chomp.to_i
a = gets.chomp.split(" ")
def bubbleSort(c, n)
a = c.dup
(0..n-1).each do |i|
(n-1).downto(i) do |j|
if a[j][1].to_i < a[j-1][1].to_i
a[j], a[j-1] = a[j-1], a[j]
end
end
end
return a
end
def selectionSort(c, n)
a = c.dup
(0..n-1).each do |i|
minj = i
(i..n-1).each do |j|
if a[j][1].to_i < a[minj][1].to_i then
minj = j
end
end
a[i], a[minj] = a[minj], a[i]
end
return a
end
bubble = bubbleSort(a, n)
selection = selectionSort(a, n)
puts bubble.join(" ")
puts "Stable"
puts selection.join(" ")
if bubble == selection then
puts "Stable"
else
puts "Not stable"
end
|
# ALDS1_2_C Stable Sort
n = gets.chomp.to_i
a = gets.chomp.split(" ")
def bubbleSort(c, n)
a = c.dup
(0..n-1).each do |i|
(n-1).downto(i+1) do |j|
if a[j][1].to_i < a[j-1][1].to_i
a[j], a[j-1] = a[j-1], a[j]
end
end
end
return a
end
def selectionSort(c, n)
a = c.dup
(0..n-1).each do |i|
minj = i
(i..n-1).each do |j|
if a[j][1].to_i < a[minj][1].to_i then
minj = j
end
end
a[i], a[minj] = a[minj], a[i]
end
return a
end
bubble = bubbleSort(a, n)
selection = selectionSort(a, n)
puts bubble.join(" ")
puts "Stable"
puts selection.join(" ")
if bubble == selection then
puts "Stable"
else
puts "Not stable"
end
|
[
"expression.operation.binary.add"
] | 108,002
| 108,000
|
u247976584
|
ruby
|
p02261
|
size = STDIN.gets.to_i
c = STDIN.gets.split
b = c.dup
size.times do |i|
(size-1).downto(i) do |j|
if b[j][1] < b[j-1][1]
b[j], b[j-1] = b[j-1], b[j]
end
end
end
puts b.join(' ')
def stable?(a1, a2)
h1 = Hash.new{|h, k| h[k] = []}
h2 = Hash.new{|h, k| h[k] = []}
a1.each do |c|
h1[c[1]] << c
end
a2.each do |c|
h2[c[1]] << c
end
h1.keys.each do |k|
if h1[k] != h2[k]
return false
end
end
return true
end
if stable?(c, b)
puts "Stable"
else
puts "Not stable"
end
s = c.dup
s.size.times do |i|
min = i
i.upto(s.size-1) do |j|
if s[j][1] < s[min][1]
min = j
end
end
if min != i
s[i], s[min] = s[min], s[i]
end
end
puts s.join(' ')
if stable?(c, s)
puts "Stable"
else
puts "Not stable"
end
|
size = STDIN.gets.to_i
c = STDIN.gets.split
b = c.dup
size.times do |i|
(size-1).downto(i+1) do |j|
if b[j][1] < b[j-1][1]
b[j], b[j-1] = b[j-1], b[j]
end
end
end
puts b.join(' ')
def stable?(a1, a2)
h1 = Hash.new{|h, k| h[k] = []}
h2 = Hash.new{|h, k| h[k] = []}
a1.each do |c|
h1[c[1]] << c
end
a2.each do |c|
h2[c[1]] << c
end
h1.keys.each do |k|
if h1[k] != h2[k]
return false
end
end
return true
end
if stable?(c, b)
puts "Stable"
else
puts "Not stable"
end
s = c.dup
s.size.times do |i|
min = i
i.upto(s.size-1) do |j|
if s[j][1] < s[min][1]
min = j
end
end
if min != i
s[i], s[min] = s[min], s[i]
end
end
puts s.join(' ')
if stable?(c, s)
puts "Stable"
else
puts "Not stable"
end
|
[
"expression.operation.binary.add"
] | 108,003
| 108,004
|
u854587684
|
ruby
|
p02261
|
class Card
attr_accessor :suit, :value
def initialize(str)
@suit = str[0]
@value = str[1].to_i
end
def to_s
"#@suit#@value"
end
def self.bubble_sort(c)
c = c.dup
n = c.size
0.upto(n-1){|i|
(n-1).downto(i){|j|
if c[j].value < c[j-1].value
c[j], c[j-1] = c[j-1], c[j]
end
}
}
c
end
def self.selection_sort(c)
c = c.dup
n = c.size
0.upto(n-1){|i|
minj = i
i.upto(n-1){|j|
if c[j].value < c[minj].value
minj = j
end
}
c[i], c[minj] = c[minj], c[i]
}
c
end
end
gets
cards = gets.split.map{|s| Card.new s }
cards1 = Card.bubble_sort(cards)
cards2 = Card.selection_sort(cards)
puts cards1*' '
puts 'Stable'
puts cards2*' '
puts cards1 == cards2 ? 'Stable' : 'Not Stable'
|
class Card
attr_accessor :suit, :value
def initialize(str)
@suit = str[0]
@value = str[1].to_i
end
def to_s
"#@suit#@value"
end
def self.bubble_sort(c)
c = c.dup
n = c.size
0.upto(n-1){|i|
(n-1).downto(i+1){|j|
if c[j].value < c[j-1].value
c[j], c[j-1] = c[j-1], c[j]
end
}
}
c
end
def self.selection_sort(c)
c = c.dup
n = c.size
0.upto(n-1){|i|
minj = i
i.upto(n-1){|j|
if c[j].value < c[minj].value
minj = j
end
}
c[i], c[minj] = c[minj], c[i]
}
c
end
end
gets
cards = gets.split.map{|s| Card.new s }
cards1 = Card.bubble_sort(cards)
cards2 = Card.selection_sort(cards)
puts cards1*' '
puts 'Stable'
puts cards2*' '
puts cards1 == cards2 ? 'Stable' : 'Not stable'
|
[
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 108,005
| 108,006
|
u422350156
|
ruby
|
p02261
|
class Card
attr_accessor :suit, :value
def initialize(str)
@suit = str[0]
@value = str[1].to_i
end
def to_s
"#@suit#@value"
end
def self.bubble_sort(c)
c = c.dup
n = c.size
0.upto(n-1){|i|
(n-1).downto(i){|j|
if c[j].value < c[j-1].value
c[j], c[j-1] = c[j-1], c[j]
end
}
}
c
end
def self.selection_sort(c)
c = c.dup
n = c.size
0.upto(n-1){|i|
minj = i
i.upto(n-1){|j|
if c[j].value < c[minj].value
minj = j
end
}
c[i], c[minj] = c[minj], c[i]
}
c
end
end
* = gets
cards = gets.split.map{|s| Card.new s }
cards1 = Card.bubble_sort(cards)
cards2 = Card.selection_sort(cards)
puts cards1*' '
puts 'Stable'
puts cards2*' '
puts cards1 == cards2 ? 'Stable' : 'Not Stable'
|
class Card
attr_accessor :suit, :value
def initialize(str)
@suit = str[0]
@value = str[1].to_i
end
def to_s
"#@suit#@value"
end
def self.bubble_sort(c)
c = c.dup
n = c.size
0.upto(n-1){|i|
(n-1).downto(i+1){|j|
if c[j].value < c[j-1].value
c[j], c[j-1] = c[j-1], c[j]
end
}
}
c
end
def self.selection_sort(c)
c = c.dup
n = c.size
0.upto(n-1){|i|
minj = i
i.upto(n-1){|j|
if c[j].value < c[minj].value
minj = j
end
}
c[i], c[minj] = c[minj], c[i]
}
c
end
end
gets
cards = gets.split.map{|s| Card.new s }
cards1 = Card.bubble_sort(cards)
cards2 = Card.selection_sort(cards)
puts cards1*' '
puts 'Stable'
puts cards2*' '
puts cards1 == cards2 ? 'Stable' : 'Not stable'
|
[
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 108,007
| 108,006
|
u422350156
|
ruby
|
p02261
|
class Card
attr_accessor :suit, :value
def initialize(str)
@suit = str[0]
@value = str[1].to_i
end
def to_s
"#@suit#@value"
end
def self.bubble_sort(c)
c = c.dup
n = c.size
0.upto(n-1){|i|
(n-1).downto(i){|j|
if c[j].value < c[j-1].value
c[j], c[j-1] = c[j-1], c[j]
end
}
}
c
end
def self.selection_sort(c)
c = c.dup
n = c.size
0.upto(n-1){|i|
minj = i
i.upto(n-1){|j|
if c[j].value < c[minj].value
minj = j
end
}
c[i], c[minj] = c[minj], c[i]
}
c
end
end
* = gets
cards = gets.split.map{|s| Card.new s }
cards1 = Card.bubble_sort(cards)
cards2 = Card.selection_sort(cards)
puts cards1*' '
puts 'Stable'
puts cards2*' '
puts cards1 == cards2 ? 'Stable' : 'Not stable'
|
class Card
attr_accessor :suit, :value
def initialize(str)
@suit = str[0]
@value = str[1].to_i
end
def to_s
"#@suit#@value"
end
def self.bubble_sort(c)
c = c.dup
n = c.size
0.upto(n-1){|i|
(n-1).downto(i+1){|j|
if c[j].value < c[j-1].value
c[j], c[j-1] = c[j-1], c[j]
end
}
}
c
end
def self.selection_sort(c)
c = c.dup
n = c.size
0.upto(n-1){|i|
minj = i
i.upto(n-1){|j|
if c[j].value < c[minj].value
minj = j
end
}
c[i], c[minj] = c[minj], c[i]
}
c
end
end
gets
cards = gets.split.map{|s| Card.new s }
cards1 = Card.bubble_sort(cards)
cards2 = Card.selection_sort(cards)
puts cards1*' '
puts 'Stable'
puts cards2*' '
puts cards1 == cards2 ? 'Stable' : 'Not stable'
|
[
"expression.operation.binary.add",
"assignment.remove"
] | 108,008
| 108,006
|
u422350156
|
ruby
|
p02261
|
def bubbleSort c, n
for i in 0...n
for j in (i...n).to_a.reverse
if c[j][1] < c[j - 1][1]
temp = c[j]
c[j] = c[j - 1]
c[j - 1] = temp
end
end
end
end
def selectionSort c, n
for i in 0...n
minj = i
for j in i...n
minj = j if c[j][1] < c[minj][1]
end
temp = c[i]
c[i] = c[minj]
c[minj] = temp
end
end
def checkOrder arr
strings = Array.new(11){""}
arr.each{|card| strings[card[1].to_i] += card[0]}
return strings
end
n = gets.to_i
arr = gets.chomp.split
arr2 = arr.dup
bubbleSort(arr2, n)
puts arr2.join(" ")
puts (checkOrder(arr) == checkOrder(arr2)) ? "Stable" : "Not stable"
arr2 = arr.dup
selectionSort(arr2, n)
puts arr2.join(" ")
puts (checkOrder(arr) == checkOrder(arr2)) ? "Stable" : "Not stable"
|
def bubbleSort c, n
for i in 1...n
for j in (i...n).to_a.reverse
if c[j][1] < c[j - 1][1]
temp = c[j]
c[j] = c[j - 1]
c[j - 1] = temp
end
end
end
end
def selectionSort c, n
for i in 0...n
minj = i
for j in i...n
minj = j if c[j][1] < c[minj][1]
end
temp = c[i]
c[i] = c[minj]
c[minj] = temp
end
end
def checkOrder arr
strings = Array.new(11){""}
arr.each{|card| strings[card[1].to_i] += card[0]}
return strings
end
n = gets.to_i
arr = gets.chomp.split
arr2 = arr.dup
bubbleSort(arr2, n)
puts arr2.join(" ")
puts (checkOrder(arr) == checkOrder(arr2)) ? "Stable" : "Not stable"
arr2 = arr.dup
selectionSort(arr2, n)
puts arr2.join(" ")
puts (checkOrder(arr) == checkOrder(arr2)) ? "Stable" : "Not stable"
|
[
"literal.number.integer.change"
] | 108,013
| 108,014
|
u247371045
|
ruby
|
p02261
|
def b_sort(ca)
c = ca.dup
s = 0
c.sort_by{|i| [i[1], s += 1]}
end
def s_sort(ca)
c = ca.dup
c.size.times do |i|
m = i
i.upto(c.size - 1) do |j|
if c[j][1] < c[m][1]
m = j
end
end
c[m], c[i] = c[m], c[i]
end
c
end
gets
a = gets.split.map! do |e|
e =~ /(\w)(\d+)/
[$1, $2.to_i]
end
b, c = [b_sort(a), s_sort(a)].map do |d|
d.map(&:join).join(' ')
end
puts b
puts 'Stable'
puts c
puts b == c ? 'Stable' : 'Not stable'
|
def b_sort(ca)
c = ca.dup
s = 0
c.sort_by{|i| [i[1], s += 1]}
end
def s_sort(ca)
c = ca.dup
c.size.times do |i|
m = i
i.upto(c.size - 1) do |j|
if c[j][1] < c[m][1]
m = j
end
end
c[m], c[i] = c[i], c[m]
end
c
end
gets
a = gets.split.map! do |e|
e =~ /(\w)(\d+)/
[$1, $2.to_i]
end
b, c = [b_sort(a), s_sort(a)].map do |d|
d.map(&:join).join(' ')
end
puts b
puts 'Stable'
puts c
puts b == c ? 'Stable' : 'Not stable'
|
[
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change"
] | 108,018
| 108,019
|
u295404099
|
ruby
|
p02261
|
def b_sort(ca)
c = ca.dup
s = 0
c.sort_by{|i| [i[1], s += 1]}
end
def s_sort(ca)
c = ca.dup
c.size.times do |i|
m = i
i.upto(c.size - 1) do |j|
if c[j][1] < c[m][1]
m = j
end
end
c[m], c[i] = c[i], c[m]
end
c
end
gets
a = gets.split.map do |e|
e =~ /(\w)(\d+)/
[$1, $2.to_i]
end
b, c = [b_sort(a), s_sort(a)].map do |d|
d.map(&:join).join(' ')
end
puts "#{b}/nStable"
puts "#{c}/n#{b == c ? 'Stable' : 'Not stable'}"
|
def b_sort(ca)
c = ca.dup
s = 0
c.sort_by{|i| [i[1], s += 1]}
end
def s_sort(ca)
c = ca.dup
c.size.times do |i|
m = i
i.upto(c.size - 1) do |j|
if c[j][1] < c[m][1]
m = j
end
end
c[m], c[i] = c[i], c[m]
end
c
end
gets
a = gets.split.map do |e|
e =~ /(\w)(\d+)/
[$1, $2.to_i]
end
b, c = [b_sort(a), s_sort(a)].map do |d|
d.map(&:join).join(' ')
end
puts "#{b}\nStable"
puts "#{c}\n#{b == c ? 'Stable' : 'Not stable'}"
|
[
"literal.string.change",
"call.arguments.change"
] | 108,020
| 108,021
|
u295404099
|
ruby
|
p02261
|
def b_sort(ca)
c = ca.dup
s = 0
c.sort_by{|i| [i[1], s += 1]}
end
def s_sort(ca)
c = ca.dup
c.size.times do |i|
m = i
i.upto(c.size - 1) do |j|
if c[j][1] < c[m][1]
m = j
end
end
c[m], c[i] = c[m], c[i]
end
c
end
gets
a = gets.split.map! do |e|
e =~ /(\w)(\d+)/
[$1, $2.to_i]
end
b, c = [b_sort(a), s_sort(a)].map do |d|
d.map(&:join).join(' ')
end
puts b
puts 'Stable'
puts c
puts b == c ? 'Stable' : 'Not stable'
|
def b_sort(ca)
c = ca.dup
s = 0
c.sort_by{|i| [i[1], s += 1]}
end
def s_sort(ca)
c = ca.dup
c.size.times do |i|
m = i
i.upto(c.size - 1) do |j|
if c[j][1] < c[m][1]
m = j
end
end
c[m], c[i] = c[i], c[m]
end
c
end
gets
a = gets.split.map do |e|
e =~ /(\w)(\d+)/
[$1, $2.to_i]
end
b, c = [b_sort(a), s_sort(a)].map do |d|
d.map(&:join).join(' ')
end
puts b
puts 'Stable'
puts c
puts b == c ? 'Stable' : 'Not stable'
|
[
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change"
] | 108,018
| 108,022
|
u295404099
|
ruby
|
p02261
|
n = gets.chomp.to_i
arr1 = gets.chomp.split(' ')
arr2 = []
(0...n).each do |i|
arr1[i] = arr1[i].split('')
arr1[i][1] = arr1[i][1].to_i
arr2[i] = arr1[i]
end
def is_same?(arr1, arr2, n)
(0...n).each do |i|
if arr1[i] != arr2[i]
return false
end
end
return true
end
def bubble_sort(arr, n)
swap_times = 0
flag = true
i = 0
while flag && i < n - 1
flag = false
j = n - 1
while j >= i + 1
if arr[j][1] < arr[j - 1][1]
swap_times += 1
tmp = arr[j]
arr[j] = arr[j - 1]
arr[j - 1] = tmp
flag = true
end
j -= 1
end
i += 1
end
end
def selection_sort(arr, n)
swap_times = 0
(0..n-2).each do |i|
minj = i
(i..n-1).each do |j|
if arr[j][1] < arr[minj][1]
minj = j
end
end
tmp = arr[i]
arr[i] = arr[minj]
arr[minj] = tmp
if i != minj
swap_times += 1
end
end
end
bubble_sort(arr1, n)
print "#{arr1.map { |obj| obj.join }.join(' ')}\nStable\n"
selection_sort(arr2, n)
print "#{arr2.map { |obj| obj.join }.join(' ')}\n"
if is_same?(arr1, arr2, n)
print "Stable\n"
else
print "Not Stable\n"
end
|
n = gets.chomp.to_i
arr1 = gets.chomp.split(' ')
arr2 = []
(0...n).each do |i|
arr1[i] = arr1[i].split('')
arr1[i][1] = arr1[i][1].to_i
arr2[i] = arr1[i]
end
def is_same?(arr1, arr2, n)
(0...n).each do |i|
if arr1[i] != arr2[i]
return false
end
end
return true
end
def bubble_sort(arr, n)
swap_times = 0
flag = true
i = 0
while flag && i < n - 1
flag = false
j = n - 1
while j >= i + 1
if arr[j][1] < arr[j - 1][1]
swap_times += 1
tmp = arr[j]
arr[j] = arr[j - 1]
arr[j - 1] = tmp
flag = true
end
j -= 1
end
i += 1
end
end
def selection_sort(arr, n)
swap_times = 0
(0..n-2).each do |i|
minj = i
(i..n-1).each do |j|
if arr[j][1] < arr[minj][1]
minj = j
end
end
tmp = arr[i]
arr[i] = arr[minj]
arr[minj] = tmp
if i != minj
swap_times += 1
end
end
end
bubble_sort(arr1, n)
print "#{arr1.map { |obj| obj.join }.join(' ')}\nStable\n"
selection_sort(arr2, n)
print "#{arr2.map { |obj| obj.join }.join(' ')}\n"
if is_same?(arr1, arr2, n)
print "Stable\n"
else
print "Not stable\n"
end
|
[
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 108,023
| 108,024
|
u799048341
|
ruby
|
p02261
|
n = gets
arr = gets.chomp.split
arro = arr.clone
arr0 = arr.clone
arr1 = arr.clone
def bubble_sort(arr)
count = 0
arr.length.times do |i|
j = arr.length - 1
while j >= i+1
if(arr[j-1][1] > arr[j][1])
tmp = arr[j-1]
arr[j-1] = arr[j]
arr[j] = tmp
end
j -= 1
end
count += 1
end
puts arr.join(' ')
puts 'Stable'
return arr
end
def select_sort(arr)
arr.length.times do |i|
mini = i
j = i
while j < arr.length
if(arr[j][1] < arr[mini][1])
mini = j
end
j += 1
end
if(i != mini)
temp = arr[i]
arr[i] = arr[mini]
arr[mini] = temp
end
end
puts arr.join(' ')
puts is_stable(@std, arr)
end
def is_stable(std, arr)
arr.length.times do |i|
return "Not stable" if(std[i] == arr[i])
end
return "Stable"
end
@std = bubble_sort(arr0)
select_sort(arr1)
|
n = gets
arr = gets.chomp.split
arro = arr.clone
arr0 = arr.clone
arr1 = arr.clone
def bubble_sort(arr)
count = 0
arr.length.times do |i|
j = arr.length - 1
while j >= i+1
if(arr[j-1][1] > arr[j][1])
tmp = arr[j-1]
arr[j-1] = arr[j]
arr[j] = tmp
end
j -= 1
end
count += 1
end
puts arr.join(' ')
puts 'Stable'
return arr
end
def select_sort(arr)
arr.length.times do |i|
mini = i
j = i
while j < arr.length
if(arr[j][1] < arr[mini][1])
mini = j
end
j += 1
end
if(i != mini)
temp = arr[i]
arr[i] = arr[mini]
arr[mini] = temp
end
end
puts arr.join(' ')
puts is_stable(@std, arr)
end
def is_stable(std, arr)
arr.length.times do |i|
return "Not stable" if(std[i] != arr[i])
end
return "Stable"
end
@std = bubble_sort(arr0)
select_sort(arr1)
|
[
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 108,025
| 108,026
|
u352940122
|
ruby
|
p02261
|
def bubble_sort(array, n)
n.times do |i|
(n - 1).downto(i + 1) do |j|
if array[j].num < array[j - 1].num
array[j], array[j - 1] = array[j - 1], array[j]
end
end
end
array
end
def selection_sort(array, n)
n.times do |i|
minj = i
i.upto(n - 1) do |j|
minj = j if array[j].num < array[minj].num
end
array[i], array[minj] = array[minj], array[i]
end
array
end
# 安定化どうか判定 バブルソートと比較して判定
def is_stable?(bubble, sorted)
bubble.each_with_index do |element, index|
return false if element.mark == sorted[index].mark
end
return true
end
class Card
def initialize(mark, num)
@mark = mark
@num = num
end
attr_accessor :mark, :num
def to_s
@mark + @num
end
end
n = gets.to_i
cards = gets.split(' ').map do |card|
Card.new(card[0], card[1])
end
cards2 = cards.clone
bubble = bubble_sort(cards, n)
selection = selection_sort(cards2, n)
puts bubble.map(&:to_s).join(' ')
puts 'Stable'
puts selection.map(&:to_s).join(' ')
if is_stable? bubble, selection
puts 'Stable'
else
puts 'Not stable'
end
|
def bubble_sort(array, n)
n.times do |i|
(n - 1).downto(i + 1) do |j|
if array[j].num < array[j - 1].num
array[j], array[j - 1] = array[j - 1], array[j]
end
end
end
array
end
def selection_sort(array, n)
n.times do |i|
minj = i
i.upto(n - 1) do |j|
minj = j if array[j].num < array[minj].num
end
array[i], array[minj] = array[minj], array[i]
end
array
end
# 安定化どうか判定 バブルソートと比較して判定
def stable?(bubble, sorted)
bubble.each_with_index do |element, index|
return false if element.mark != sorted[index].mark
end
true
end
class Card
def initialize(mark, num)
@mark = mark
@num = num
end
attr_accessor :mark, :num
def to_s
@mark + @num
end
end
n = gets.to_i
cards = gets.split(' ').map do |card|
Card.new(card[0], card[1])
end
cards2 = cards.clone
bubble = bubble_sort(cards, n)
selection = selection_sort(cards2, n)
puts bubble.map(&:to_s).join(' ')
puts 'Stable'
puts selection.map(&:to_s).join(' ')
if stable? bubble, selection
puts 'Stable'
else
puts 'Not stable'
end
|
[
"identifier.change",
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"control_flow.return.remove"
] | 108,027
| 108,028
|
u731989230
|
ruby
|
p02262
|
# get input
n=gets.to_i
target=[]
n.times do
target << gets.to_i
end
# insertion sort method
def insertion_sort a, n, g
cnt = 0
(g..n-1).each do |i|
v = a[i]
j = i - g
while j >= 0 && a[j] > v
a[j+g] = a[j]
j = j - g
cnt+=1
end
a[j+g] = v
end
return cnt
end
# main
## g = [n]
## begin
## g << (g[-1]**(1/2.0)).to_i
## cnt = insertion_sort target, n, g[-1]
## end while g[-1] > 1
## g.delete_at(0)
g = [1]
cnt = 0
while (i = 3 * g[0] + 1) < n do
g.unshift i
end
g.each do |i|
cnt = insertion_sort target, n, i
end
# output
puts g.length
puts g*' '
puts cnt
target.each do |i|
puts i
end
|
# get input
n=gets.to_i
target=[]
n.times do
target << gets.to_i
end
# insertion sort method
def insertion_sort a, n, g
cnt = 0
(g..n-1).each do |i|
v = a[i]
j = i - g
while j >= 0 && a[j] > v
a[j+g] = a[j]
j = j - g
cnt+=1
end
a[j+g] = v
end
return cnt
end
# main
g = [1]
cnt = 0
while (i = 3 * g[0] + 1) < n do
g.unshift i
end
g.each do |i|
cnt += insertion_sort target, n, i
end
# output
puts g.length
puts g*' '
puts cnt
target.each do |i|
puts i
end
|
[
"assignment.value.change"
] | 109,198
| 109,199
|
u352522848
|
ruby
|
p02262
|
n=gets.chomp.to_i
ary=Array.new
for i in 0..n-1
ary=ary.push(gets.chomp.to_i)
end
def insertion(ary,n,g)
for i in g..n-1
v=ary[i]
j=i-g
while j>=0 && ary[j]>v
ary[j+g]=ary[j]
j-=g
@count+=1
end
ary[j+g]=v
end
end
g=1
while 3*g+1<=n
g=3*g+1
end
@count=0
k=Array.new
while g>=1
insertion(ary,n,g)
k=k.push(g)
g=(g-1)/3
end
puts(k.join(" "))
puts @count
puts(ary)
|
n=gets.chomp.to_i
ary=Array.new
for i in 0..n-1
ary=ary.push(gets.chomp.to_i)
end
def insertion(ary,n,g)
for i in g..n-1
v=ary[i]
j=i-g
while j>=0 && ary[j]>v
ary[j+g]=ary[j]
j-=g
@count+=1
end
ary[j+g]=v
end
end
g=1
while 3*g+1<=n
g=3*g+1
end
@count=0
k=Array.new
while g>=1
insertion(ary,n,g)
k=k.push(g)
g=(g-1)/3
end
puts(k.size)
puts(k.join(" "))
puts @count
puts (ary)
|
[
"call.add"
] | 109,202
| 109,203
|
u534464795
|
ruby
|
p02262
|
def insertion_sort(array, n, g)
cnt = 0
g.upto n - 1 do |i|
v = array[i]
j = i - g
while j >= 0 && array[j] > v
array[j + g] = array[j]
j -= g
cnt += 1
end
array[j + g] = v
end
cnt
end
def shell_sort(array, n)
cnt = 0
g = [1]
g << 3 * g[-1] + 1 until 3 * g[-1] + 1 > n
m = g.length
g.reverse_each do |value|
cnt += insertion_sort(array, n, value)
end
[array, cnt, m, g]
end
n = gets.to_i
array = []
n.times do
array << gets.to_i
end
result = shell_sort array, n
puts result[2]
puts result[3].join(' ')
puts result[1]
puts result[0]
|
def insertion_sort(array, n, g)
cnt = 0
g.upto n - 1 do |i|
v = array[i]
j = i - g
while j >= 0 && array[j] > v
array[j + g] = array[j]
j -= g
cnt += 1
end
array[j + g] = v
end
cnt
end
def shell_sort(array, n)
cnt = 0
g = [1]
g << 3 * g[-1] + 1 until 3 * g[-1] + 1 > n
m = g.length
g.reverse_each do |value|
cnt += insertion_sort(array, n, value)
end
[array, cnt, m, g]
end
n = gets.to_i
array = []
n.times do
array << gets.to_i
end
result = shell_sort array, n
puts result[2]
puts result[3].reverse.join(' ')
puts result[1]
puts result[0]
|
[
"call.add"
] | 109,210
| 109,211
|
u731989230
|
ruby
|
p02262
|
#!/usr/bin/ruby
def insertionSort(a, n, g)
for i in g..n-1
v = a[i]
j = i - g
while j >= 0 && a[j] > v
a[j+g] = a[j]
j = j - g
$cnt+=1
a[j+g] = v
end
end
end
def shellSort(a, n)
$cnt = 0
g = []
h = 1
while h*2 <= n
g << h
h = 3*h+1
end
g.reverse!
m = g.size
p m
puts g*' '
for i in 0..m-1
insertionSort(a, n, g[i])
end
end
#a=[9,8,5,1,7,4,6,3,2]
a=gets.to_i.times.map{gets.to_i}
shellSort(a,a.size)
p $cnt
puts a
|
#!/usr/bin/ruby
def insertionSort(a, n, g)
for i in g..n-1
v = a[i]
j = i - g
while j >= 0 && a[j] > v
a[j+g] = a[j]
j = j - g
$cnt+=1
a[j+g] = v
end
end
end
def shellSort(a, n)
$cnt = 0
g = []
h = 1
while h <= n
g << h
h = 3*h+1
end
g.reverse!
m = g.size
p m
puts g*' '
for i in 0..m-1
insertionSort(a, n, g[i])
end
end
#a=[9,8,5,1,7,4,6,3,2]
a=gets.to_i.times.map{gets.to_i}
shellSort(a,a.size)
p $cnt
puts a
|
[] | 109,213
| 109,214
|
u300645821
|
ruby
|
p02262
|
#!/usr/bin/ruby
def insertionSort(a,g)
for i in g..a.size-1
v = a[i]
j = i - g
while j >= 0 && a[j] > v
a[j+g] = a[j]
j = j - g
$cnt+=1
a[j+g] = v
end
end
end
def shellSort(a)
$cnt = 0
g = []
h = 1
while h <= a.size
g << h
h = 3*h+1
end
g.reverse!
m = g.size
p m
puts g*' '
for i in 0..m-1
insertionSort(a,g[i])
end
end
a=gets.to_i.times.map{gets.to_i}
shellSort(a,a.size)
p $cnt
puts a
|
#!/usr/bin/ruby
def insertionSort(a,g)
for i in g..a.size-1
v = a[i]
j = i - g
while j >= 0 && a[j] > v
a[j+g] = a[j]
j = j - g
$cnt+=1
a[j+g] = v
end
end
end
def shellSort(a)
$cnt = 0
g = []
h = 1
while h <= a.size
g << h
h = 3*h+1
end
g.reverse!
m = g.size
p m
puts g*' '
for i in 0..m-1
insertionSort(a,g[i])
end
end
a=gets.to_i.times.map{gets.to_i}
shellSort(a)
p $cnt
puts a
|
[
"call.arguments.change"
] | 109,215
| 109,216
|
u300645821
|
ruby
|
p02264
|
def roundRobin(q, process, time)
currentTime = 0
loop do
break if process.empty?
p = process.shift
t = time.shift
if t <= q
currentTime += t
puts p + " " + currentTime.to_s
else
t -= q
process.push p
time.push t
currentTime += q
end
end
end
if __FILE__ == $0
n, q = gets.split.map(&:to_i)
process = []
time = []
n.times do
p, t = gets.chomp.split
process << p
time << t.to_i
end
p time
roundRobin q, process, time
end
|
def roundRobin(q, process, time)
currentTime = 0
loop do
break if process.empty?
p = process.shift
t = time.shift
if t <= q
currentTime += t
puts p + " " + currentTime.to_s
else
t -= q
process.push p
time.push t
currentTime += q
end
end
end
if __FILE__ == $0
n, q = gets.split.map(&:to_i)
process = []
time = []
n.times do
p, t = gets.chomp.split
process << p
time << t.to_i
end
roundRobin q, process, time
end
|
[
"call.remove"
] | 109,677
| 109,678
|
u881491942
|
ruby
|
p02264
|
class Task
def initialize(name, qms)
@name = name
if !qms.is_a? Integer
qms = qms.to_i
end
@qms = qms
end
def consume(time)
@qms -= time
end
def to_s
"#{@name}"
end
end
n, consume_time = STDIN.gets.split.map(&:to_i)
queue = []
n.times do
pname, ptime = STDIN.gets.split
queue.push(Task.new(pname, ptime))
end
past_time = 0
until queue.empty?
task = queue.shift
remain = task.consume(consume_time)
if remain > 0
past_time += 100
queue.push(task)
else
past_time += consume_time + remain # remainはマイナスなので
puts "#{task.to_s} #{past_time}"
end
end
|
class Task
def initialize(name, qms)
@name = name
if !qms.is_a? Integer
qms = qms.to_i
end
@qms = qms
end
def consume(time)
@qms -= time
end
def to_s
"#{@name}"
end
end
n, consume_time = STDIN.gets.split.map(&:to_i)
queue = []
n.times do
pname, ptime = STDIN.gets.split
queue.push(Task.new(pname, ptime))
end
past_time = 0
until queue.empty?
task = queue.shift
remain = task.consume(consume_time)
if remain > 0
past_time += consume_time
queue.push(task)
else
past_time += consume_time + remain # ここでremainはマイナスなので
puts "#{task.to_s} #{past_time}"
end
end
|
[
"identifier.replace.add",
"literal.replace.remove"
] | 109,679
| 109,680
|
u977801694
|
ruby
|
p02264
|
n_process, quantum = gets.chomp.split.map(&:to_i)
queue = []
n_process.times{
name, sec = gets.chomp.split
queue.push [name, sec.to_i]
}
time = 0
until queue.empty?
process = queue.shift
p process
if process[1] <= quantum
# p "?¶???????"
time += process[1]
puts "#{process[0]} #{time}"
else
# p "?¶??????????"
time += quantum
queue.push [process[0], process[1] - quantum]
# p "?????¨#{process[1] - quantum}"
end
end
|
n_process, quantum = gets.chomp.split.map(&:to_i)
queue = []
n_process.times{
name, sec = gets.chomp.split
queue.push [name, sec.to_i]
}
time = 0
until queue.empty?
process = queue.shift
# p process
if process[1] <= quantum
# p "?¶???????"
time += process[1]
puts "#{process[0]} #{time}"
else
# p "?¶??????????"
time += quantum
queue.push [process[0], process[1] - quantum]
# p "?????¨#{process[1] - quantum}"
end
end
|
[
"call.remove"
] | 109,689
| 109,690
|
u677710583
|
ruby
|
p02264
|
n_process, quantum = gets.chomp.split.map(&:to_i)
queue = []
n_process.times{
name, sec = gets.chomp.split
queue.push [name, sec.to_i]
}
time = 0
until queue.empty?
process = queue.shift
p process
if process[1] <= quantum
# p "?¶???????"
time += process[1]
puts "#{process[0]} #{time}"
else
# p "?¶??????????"
time += quantum
queue.push [process[0], process[1] - quantum]
# p "?????¨#{process[1] - quantum}"
end
end
|
n, quantum = gets.chomp.split.map(&:to_i)
queue = []
n.times{
name, sec = gets.chomp.split
queue.push [name, sec.to_i]
}
time = 0
until queue.empty?
process = queue.shift
# p process
if process[1] <= quantum
# p "?¶???????"
time += process[1]
puts "#{process[0]} #{time}"
else
# p "?¶??????????"
time += quantum
queue.push [process[0], process[1] - quantum]
# p "?????¨#{process[1] - quantum}"
end
end
|
[
"assignment.variable.change",
"identifier.change",
"call.remove"
] | 109,689
| 109,691
|
u677710583
|
ruby
|
p02264
|
line1 = STDIN.gets.chomp.split(" ")
n = line1[0].to_i
q = line1[1].to_i
queue = Array.new(n)
n.times do |i|
line = STDIN.gets.chomp.split(" ")
process = [line[0], line[1].to_i]
queue[i] = process
end
time = 0
processes_ended = Array.new
while queue.empty? == false
process = queue.shift
if process[1] > q
time += q
process[1] -= q
queue.push(process)
else
time += process.time
process[1] -= process.time
puts "#{process[0]} #{time}"
end
end
|
line1 = STDIN.gets.chomp.split(" ")
n = line1[0].to_i
q = line1[1].to_i
queue = Array.new(n)
n.times do |i|
line = STDIN.gets.chomp.split(" ")
process = [line[0], line[1].to_i]
queue[i] = process
end
time = 0
processes_ended = Array.new
while queue.empty? == false
process = queue.shift
if process[1] > q
time += q
process[1] -= q
queue.push(process)
else
time += process[1]
process[1] -= process[1]
puts "#{process[0]} #{time}"
end
end
|
[] | 109,694
| 109,695
|
u818475907
|
ruby
|
p02264
|
n,q = gets.split.map(&:to_i)
queue = []
n.times{
queue << gets.split
}
# n,q=5,100
# queue = [["p1",150],["p2",80],["p3",200],["p4",350],["p5",20]]
# time = 0
def aqueue(n,q,queue,time)
ans = []
while queue.size != 0
v = queue.shift
if v[1].to_i <= q
time += v[1].to_i
ans.push("#{v[0]} #{time}")
else
time += q
v[1] = v[1].to_i - q
queue.push(v)
end
end
return ans
end
puts aqueue(n,q,queue,time)
|
n,q = gets.split.map(&:to_i)
queue = []
n.times{
queue << gets.split
}
# n,q=5,100
# queue = [["p1",150],["p2",80],["p3",200],["p4",350],["p5",20]]
time = 0
def aqueue(n,q,queue,time)
ans = []
while queue.size != 0
v = queue.shift
if v[1].to_i <= q
time += v[1].to_i
ans.push("#{v[0]} #{time}")
else
time += q
v[1] = v[1].to_i - q
queue.push(v)
end
end
return ans
end
puts aqueue(n,q,queue,time)
|
[
"assignment.add"
] | 109,698
| 109,699
|
u151409041
|
ruby
|
p02264
|
n, q = gets.chomp.split(' ').map(&:to_i)
arr = []
(0...n).each do |i|
arr[i]= gets.chomp.split(' ')
end
class Queue
attr_accessor :head, :tail, :queue
def initialize(size)
@head = 0
@tail = 0
@queue = Array.new(size)
end
def enqueue(x)
@queue[@tail] = x
if @tail + 1 == @queue.size
@tail = 0
else
@tail += 1
end
end
def dequeue
x = @queue[@head]
if @head + 1 == @queue.size
@head = 0
else
@head += 1
end
return x
end
def isEmpty?
return @head == @tail
end
def isFull?
return @head == (@tail + 1) % @queue.size
end
end
queue = Queue.new(n + 1)
time = 0
(0...n).each do |i|
queue.enqueue(arr[i])
end
while !queue.isEmpty?
process = queue.dequeue
if process[1].to_i > q
process[1] = process[1].to_i - q
time += 100
queue.enqueue(process)
else
time += process[1].to_i
print "#{process[0]} #{time}\n"
end
end
|
n, q = gets.chomp.split(' ').map(&:to_i)
arr = []
(0...n).each do |i|
arr[i]= gets.chomp.split(' ')
end
class Queue
attr_accessor :head, :tail, :queue
def initialize(size)
@head = 0
@tail = 0
@queue = Array.new(size)
end
def enqueue(x)
@queue[@tail] = x
if @tail + 1 == @queue.size
@tail = 0
else
@tail += 1
end
end
def dequeue
x = @queue[@head]
if @head + 1 == @queue.size
@head = 0
else
@head += 1
end
return x
end
def isEmpty?
return @head == @tail
end
def isFull?
return @head == (@tail + 1) % @queue.size
end
end
queue = Queue.new(n + 1)
time = 0
(0...n).each do |i|
queue.enqueue(arr[i])
end
while !queue.isEmpty?
process = queue.dequeue
if process[1].to_i > q
process[1] = process[1].to_i - q
time += q
queue.enqueue(process)
else
time += process[1].to_i
print "#{process[0]} #{time}\n"
end
end
|
[
"identifier.replace.add",
"literal.replace.remove"
] | 109,700
| 109,701
|
u799048341
|
ruby
|
p02264
|
class Proces
def initialize(name,time)
@name = name
@time = time.to_i
end
def act limit
if @time > limit
@time -= limit
true
end
false
end
attr_reader :name,:time
end
queue = Array.new()
time = 0
temp = gets.split(" ").map{|x| x.to_i}
q = temp.pop
num = temp.pop
num.times do
temp = gets.split(" ")
queue.push(Proces.new(temp[0],temp[1]))
end
until (p = queue.shift) == nil ? true:false
if p.act(q)
queue.push(p)
time += q
else
time+=p.time
printf("%s %d\n",p.name,time)
end
end
|
class Proces
def initialize(name,time)
@name = name
@time = time.to_i
end
def act limit
if @time > limit
@time -= limit
true
end
end
attr_reader :name,:time
end
queue = Array.new()
time = 0
temp = gets.split(" ").map{|x| x.to_i}
q = temp.pop
num = temp.pop
num.times do
temp = gets.split(" ")
queue.push(Proces.new(temp[0],temp[1]))
end
until (p = queue.shift) == nil ? true:false
if p.act(q)
queue.push(p)
time += q
else
time+=p.time
printf("%s %d\n",p.name,time)
end
end
|
[] | 109,704
| 109,705
|
u588130269
|
ruby
|
p02263
|
ary=gets.chomp.split(" ")
stack=[]
c=[]
ary.each {|x|
if x =~ /\d+/
x=x.to_i
stack.unshift(x)
p stack
c=nil
elsif x== "+" || x=="-" || x=="*" || x=="/"
b=stack.shift
a=stack.shift
case x
when "+"
stack=stack.unshift(a+b)
when "-"
stack=stack.unshift(a-b)
when "*"
stack=stack.unshift(a*b)
when "/"
stack=stack.unshift(a/b)
end
end
}
puts stack
|
ary=gets.chomp.split(" ")
stack=[]
c=[]
ary.each {|x|
if x =~ /\d+/
x=x.to_i
stack.unshift(x)
c=nil
elsif x== "+" || x=="-" || x=="*" || x=="/"
b=stack.shift
a=stack.shift
case x
when "+"
stack=stack.unshift(a+b)
when "-"
stack=stack.unshift(a-b)
when "*"
stack=stack.unshift(a*b)
when "/"
stack=stack.unshift(a/b)
end
end
}
puts stack
|
[
"call.remove"
] | 109,803
| 109,804
|
u534464795
|
ruby
|
p02263
|
input_str = STDIN.gets
input_list = input_str.split(" ")
stack = []
input_list.each do |value|
case value
when '+'
a = stack.pop
b = stack.pop
c = a + b
stack.push c
when '-'
a = stack.pop
b = stack.pop
c = a - b
stack.push c
when '*'
a = stack.pop
b = stack.pop
c = a * b
stack.push c
else
value_int = value.to_i
stack.push value_int
end
end
answer = stack.pop
puts answer.to_i
|
input_str = STDIN.gets
input_list = input_str.split(" ")
stack = []
input_list.each do |value|
case value
when '+'
b = stack.pop
a = stack.pop
c = a + b
stack.push c
when '-'
b = stack.pop
a = stack.pop
c = a - b
stack.push c
when '*'
b = stack.pop
a = stack.pop
c = a * b
stack.push c
else
value_int = value.to_i
stack.push value_int
end
end
answer = stack.pop
puts answer.to_i
|
[
"assignment.variable.change",
"identifier.change"
] | 109,807
| 109,808
|
u188708842
|
ruby
|
p02263
|
#一つの数式が一行に与えられます
#連続するシンボルは一つの空白で区切られて与えられます
#計算結果を一行に出力してください
require "pp"
input = gets.chomp.split(" ")
stack = %w[]
input.each do |str|
if str =~ /^[0-9]/
stack.push str
else
if str == "+"
second = stack.pop.to_i
first = stack.pop.to_i
stack.push(first-second)
elsif str == "-"
second = stack.pop.to_i
first = stack.pop.to_i
stack.push(first-second)
elsif str == "*"
second = stack.pop.to_i
first = stack.pop.to_i
stack.push(second*first)
end
end
end
puts stack[0]
|
#一つの数式が一行に与えられます
#連続するシンボルは一つの空白で区切られて与えられます
#計算結果を一行に出力してください
require "pp"
input = gets.chomp.split(" ")
stack = %w[]
input.each do |str|
if str =~ /^[0-9]/
stack.push str
else
if str == "+"
second = stack.pop.to_i
first = stack.pop.to_i
stack.push(first+second)
elsif str == "-"
second = stack.pop.to_i
first = stack.pop.to_i
stack.push(first-second)
elsif str == "*"
second = stack.pop.to_i
first = stack.pop.to_i
stack.push(second*first)
end
end
end
puts stack[0]
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 109,810
| 109,811
|
u483082413
|
ruby
|
p02265
|
# 双方向連結リスト | アルゴリズムとデータ構造 | Aizu Online Judge http://is.gd/5CIlit
n = gets.chomp.to_i
doubleLinkedList = Array.new
n.times do
command = gets.chomp
if command == "deleteFirst" then
doubleLinkedList.shift
elsif command == "deleteLast" then
doubleLinkedList.pop
else
command, x = command.split
x = x.to_i
if command == "insert" then
doubleLinkedList.unshift(x)
elsif command == "delete" then
i = doubleLinkedList.index(x)
doubleLinkedList.delete_at(i)
end
end
end
puts doubleLinkedList.join(" ")
|
# 双方向連結リスト | アルゴリズムとデータ構造 | Aizu Online Judge http://is.gd/5CIlit
n = gets.chomp.to_i
doubleLinkedList = Array.new
n.times do
command = gets.chomp
if command == "deleteFirst" then
doubleLinkedList.shift
elsif command == "deleteLast" then
doubleLinkedList.pop
else
command, x = command.split
x = x.to_i
if command == "insert" then
doubleLinkedList.unshift(x)
elsif command == "delete" then
i = doubleLinkedList.index(x)
doubleLinkedList.delete_at(i) if !i.nil?
end
end
end
puts doubleLinkedList.join(" ")
|
[] | 110,169
| 110,170
|
u247976584
|
ruby
|
p02265
|
class List
def initialize
@head = Node.new
@tail = Node.new(@head)
@head.nxt = @tail
end
def insert(val)
nxt_old = @head.nxt
node = Node.new(@head, nxt_old, val)
@head.nxt = node
nxt_old.prv = node
end
def delete(val)
node = @head.nxt
while node.val
if node.val == val
node.prv.nxt = node.nxt
node.nxt.prv = node.prv
return
end
node = node.nxt
end
end
def delete_first
raise 'List is mpety.' if @head.nxt == @tail
@head.nxt = @head.nxt.nxt
@head.nxt.prv = @head
end
def delete_last
raise 'List is mpety.' if @head.nxt == @tail
@tail.prv = @tail.prv.prv
@tail.prv.nxt = @tail
end
def to_s
vals = []
node = @head.nxt
while node.val
vals << node.val
node = node.nxt
end
vals.join(' ')
end
class Node
attr_accessor :prv, :nxt, :val
def initialize(prv = nil, nxt = nil, val = nil)
@prv = prv
@nxt = nxt
@val = val
end
end
end
list = List.new
STDIN.read.split(/\n/)[1..-1].each do |line|
ary = line.split(/\s/)
command = ary[0]
#start = Time.now
case command
when 'insert' then
list.insert ary[1].to_i
when 'delete' then
list.delete ary[1].to_i
when 'deleteFirst' then
list.delete_first
when 'deleteLast' then
list.delete_last
end
end
|
class List
def initialize
@head = Node.new
@tail = Node.new(@head)
@head.nxt = @tail
end
def insert(val)
nxt_old = @head.nxt
node = Node.new(@head, nxt_old, val)
@head.nxt = node
nxt_old.prv = node
end
def delete(val)
node = @head.nxt
while node.val
if node.val == val
node.prv.nxt = node.nxt
node.nxt.prv = node.prv
return
end
node = node.nxt
end
end
def delete_first
raise 'List is mpety.' if @head.nxt == @tail
@head.nxt = @head.nxt.nxt
@head.nxt.prv = @head
end
def delete_last
raise 'List is mpety.' if @head.nxt == @tail
@tail.prv = @tail.prv.prv
@tail.prv.nxt = @tail
end
def to_s
vals = []
node = @head.nxt
while node.val
vals << node.val
node = node.nxt
end
vals.join(' ')
end
class Node
attr_accessor :prv, :nxt, :val
def initialize(prv = nil, nxt = nil, val = nil)
@prv = prv
@nxt = nxt
@val = val
end
end
end
list = List.new
STDIN.read.split(/\n/)[1..-1].each do |line|
ary = line.split(/\s/)
command = ary[0]
#start = Time.now
case command
when 'insert' then
list.insert ary[1].to_i
when 'delete' then
list.delete ary[1].to_i
when 'deleteFirst' then
list.delete_first
when 'deleteLast' then
list.delete_last
end
end
puts list.to_s
|
[
"call.add"
] | 110,171
| 110,172
|
u631235380
|
ruby
|
p02265
|
n = gets.to_i
command_list = []
n.times do
command_list << gets.chomp.split
end
list = []
while command_list.length > 0
command = command_list.shift
if command[0] == "insert"
list << command[1].to_i
elsif command[0] == "delete"
x = list.rindex(command[1].to_i)
list.delete_at(x)
elsif command[0] == "deleteFirst"
list.pop
elsif command[0] == "deleteLast"
list.shift
end
end
puts list.reverse.join(" ")
|
n = gets.to_i
command_list = []
n.times do
command_list << gets.chomp.split
end
list = []
while command_list.length > 0
command = command_list.shift
if command[0] == "insert"
list << command[1].to_i
elsif command[0] == "delete"
x = list.rindex(command[1].to_i)
if x
list.delete_at(x)
end
elsif command[0] == "deleteFirst"
list.pop
elsif command[0] == "deleteLast"
list.shift
end
end
puts list.reverse.join(" ")
|
[] | 110,178
| 110,179
|
u536840698
|
ruby
|
p02265
|
#!/usr/bin/env ruby
n = gets.chomp.to_i
list = []
n.times do
action, num = gets.chomp.split
case action
when 'insert'
list.unshift(num.to_i)
when 'delete'
i = list.index(num.to_i)
list.delete_at(i) if i
when 'deleteFirst'
list.shift
when 'deleteLast'
list.pop
end
end
puts list.reverse * ' '
|
#!/usr/bin/env ruby
n = gets.chomp.to_i
list = []
n.times do
action, num = gets.chomp.split
case action
when 'insert'
list.unshift(num.to_i)
when 'delete'
i = list.index(num.to_i)
list.delete_at(i) if i
when 'deleteFirst'
list.shift
when 'deleteLast'
list.pop
end
end
puts list * ' '
|
[
"call.remove"
] | 110,184
| 110,185
|
u717782380
|
ruby
|
p02265
|
n = gets.chomp.to_i
arr = Array.new
n.times do
order = gets.split(" ")
case order[0]
when "insert"
arr.unshift(order[1].to_i)
when "delete"
arr.index(order[1].to_i) == nil ? (next): (queue.delete_at(queue.index(order[1].to_i)))
when "deleteFirst"
arr.shift
when "deleteLast"
arr.pop
end
end
(arr.size).times do |num|
print arr[num]
num+1 == (arr.size) ? (print "\n") : (print " ")
end
|
n = gets.chomp.to_i
arr = Array.new
n.times do
order = gets.split(" ")
case order[0]
when "insert"
arr.unshift(order[1].to_i)
when "delete"
arr.index(order[1].to_i) == nil ? (next): (arr.delete_at(arr.index(order[1].to_i)))
when "deleteFirst"
arr.shift
when "deleteLast"
arr.pop
end
end
(arr.size).times do |num|
print arr[num]
num+1 == (arr.size) ? (print "\n") : (print " ")
end
|
[
"identifier.change",
"call.arguments.change"
] | 110,186
| 110,187
|
u481175672
|
ruby
|
p02265
|
array = Array.new
gets.to_i.times do
command = gets.chomp.split
case command[0]
when 'insert'
array.unshift(command[1].to_i)
when 'delete'
array.delete_at(array.index(command[1].to_i))
when 'deleteFirst'
array.shift
when 'deleteLast'
array.pop
end
end
puts array*' '
|
array = Array.new
gets.to_i.times do
command = gets.chomp.split
case command[0]
when 'insert'
array.unshift(command[1].to_i)
when 'delete'
begin
array.delete_at(array.index(command[1].to_i))
rescue
end
when 'deleteFirst'
array.shift
when 'deleteLast'
array.pop
end
end
puts array*' '
|
[] | 110,195
| 110,196
|
u879497299
|
ruby
|
p02265
|
l = []
gets.to_i.times do
com, n = gets.split
case com
when 'insert'
l.unshift(n)
when 'delete'
i = l.index(n)
l.delete_at(i)
when 'deleteFirst'
l.shift
when 'deleteLast'
l.pop
end
end
puts l * ' '
|
l = []
gets.to_i.times do
com, n = gets.split
case com
when 'insert'
l.unshift(n)
when 'delete'
i = l.index(n)
l.delete_at(i) unless i.nil?
when 'deleteFirst'
l.shift
when 'deleteLast'
l.pop
end
end
puts l * ' '
|
[] | 110,197
| 110,198
|
u517414491
|
ruby
|
p02266
|
def solve(diagram)
area = 0
froms = []
layers = []
(0...diagram.size).each do |x|
c = diagram[x]
case c
when '\\' then
froms.push x
when '/' then
next if froms.empty?
from = froms.pop
area += 1
area += x - from - 1
layers << [from, x]
end
end
return area, layers
end
diagram = STDIN.readline
area, layers = solve(diagram)
puts area
area = 0
areas = []
last = diagram.size
layers.reverse.each do |layer|
if last < layer[0]
areas[-1] += (layer[1] - layer[0])
else
areas << layer[1] - layer[0]
last = layer[0]
end
end
print areas.size
print " " if areas.size != 1
puts areas.reverse.join(' ')
|
def solve(diagram)
area = 0
froms = []
layers = []
(0...diagram.size).each do |x|
c = diagram[x]
case c
when '\\' then
froms.push x
when '/' then
next if froms.empty?
from = froms.pop
area += 1
area += x - from - 1
layers << [from, x]
end
end
return area, layers
end
diagram = STDIN.readline
area, layers = solve(diagram)
puts area
area = 0
areas = []
last = diagram.size
layers.reverse.each do |layer|
if last < layer[0]
areas[-1] += (layer[1] - layer[0])
else
areas << layer[1] - layer[0]
last = layer[0]
end
end
print areas.size
print " " if areas.size != 0
puts areas.reverse.join(' ')
|
[
"literal.number.integer.change",
"control_flow.branch.if.condition.change"
] | 110,515
| 110,516
|
u723368439
|
ruby
|
p02267
|
n = STDIN.gets.to_i
s = STDIN.gets.split[0...n].map(&:to_i)
q = STDIN.gets.to_i
t = STDIN.gets.split[0...q].map(&:to_i)
count = 0
t.each do |te|
s[q] = te # 番兵を利用, rubyでは多分意味ない
i = 0
i += 1 until a[i] == te
count += 1 unless i == q
end
p count
|
n = STDIN.gets.to_i
s = STDIN.gets.split[0...n].map(&:to_i)
q = STDIN.gets.to_i
t = STDIN.gets.split[0...q].map(&:to_i)
count = 0
t.each do |te|
s[n] = te # 番兵を利用, rubyでは多分意味ない
i = 0
i += 1 until s[i] == te
count += 1 unless i == n
end
p count
|
[
"assignment.variable.change",
"identifier.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 111,374
| 111,375
|
u977801694
|
ruby
|
p02267
|
int_s = gets.to_i
s_arr = gets.split(" ").map(&:to_i)
int_t = gets.to_i
t_arr = gets.split(" ").map(&:to_i)
count1 = s_arr.count
count2 = (s_arr - t_arr).count
ans = count1 - count2
puts ans
|
int_s = gets.to_i
s_arr = gets.split(" ").map(&:to_i)
int_t = gets.to_i
t_arr = gets.split(" ").map(&:to_i)
count1 = s_arr.uniq.count
count2 = (s_arr.uniq - t_arr.uniq).count
ans = count1 - count2
puts ans
|
[
"call.add"
] | 111,376
| 111,377
|
u046695668
|
ruby
|
p02267
|
def linearSearch(as, bs)
n = 0
for i in as
for j in bs
if i == j
n = n + 1
end
end
end
puts n
end
a_size = STDIN.gets.to_i
as = STDIN.gets.split(' ')
b_size = STDIN.gets.to_i
bs = STDIN.gets.split(' ')
linearSearch(as, bs)
|
def linearSearch(as, bs)
n = 0
for i in bs
for j in as
if i == j
n = n + 1
break;
end
end
end
puts n
end
a_size = STDIN.gets.to_i
as = STDIN.gets.split(' ')
b_size = STDIN.gets.to_i
bs = STDIN.gets.split(' ')
linearSearch(as, bs)
|
[
"identifier.change"
] | 111,380
| 111,381
|
u382730661
|
ruby
|
p02267
|
n = gets.chomp.to_i
s = gets.chomp.split(" ").map(&:to_i)
q = gets.chomp.to_i
t = gets.chomp.split(" ").map(&:to_i)
c = 0
t.each { |i|
s.each{ |j|
if i == j
c+=1
end
}
}
puts c
|
n = gets.chomp.to_i
s = gets.chomp.split(" ").map(&:to_i)
q = gets.chomp.to_i
t = gets.chomp.split(" ").map(&:to_i)
c = 0
t.each { |i|
s.each{ |j|
if i == j
c+=1
break
end
}
}
puts c
|
[
"control_flow.break.add"
] | 111,382
| 111,383
|
u843848664
|
ruby
|
p02267
|
s = gets.split
t = gets.sprit
puts (s&t).size
|
gets
s=gets.split
gets
t=gets.split
puts (s&t).size
|
[
"assignment.value.change",
"identifier.change"
] | 111,388
| 111,389
|
u753751512
|
ruby
|
p02267
|
s = gets.split
t = gets.sprit
puts (s&t).size
|
gets
s=gets.split
gets
t=gets.split
puts (s&t).size
|
[
"assignment.value.change",
"identifier.change"
] | 111,390
| 111,389
|
u753751512
|
ruby
|
p02267
|
gets
s =gets.split
gets
t =gets.sprit
puts (s&t).size
|
gets
s=gets.split
gets
t=gets.split
puts (s&t).size
|
[
"assignment.value.change",
"identifier.change"
] | 111,392
| 111,389
|
u753751512
|
ruby
|
p02267
|
gets
s=gets.split
gets
t=gets.sprit
puts (s&t).size
|
gets
s=gets.split
gets
t=gets.split
puts (s&t).size
|
[
"assignment.value.change",
"identifier.change"
] | 111,393
| 111,389
|
u753751512
|
ruby
|
p02267
|
gets
s=gets.split
gets
t=gets.sprit
puts (s & t).size
|
gets
s=gets.split
gets
t=gets.split
puts (s&t).size
|
[
"assignment.value.change",
"identifier.change"
] | 111,394
| 111,389
|
u753751512
|
ruby
|
p02267
|
n=gets.to_i
s=gets.split.map(&:to_i)
q=gets.to_i
t=gets.split.map(&:to_i)
cnt=0
s.each do |i|
t.each do |j|
if i==j
cnt+=1
end
end
end
puts cnt
|
n=gets.to_i
s=gets.split.map(&:to_i)
q=gets.to_i
t=gets.split.map(&:to_i)
cnt=0
t.each do |i|
s.each do |j|
if i==j
cnt+=1
break
end
end
end
puts cnt
|
[
"identifier.change",
"control_flow.break.add"
] | 111,401
| 111,402
|
u083853290
|
ruby
|
p02267
|
def linear_search(array, value)
length = array.length
for i in 0..(length-1)
if array[i] == value
return true
end
end
end
n = gets.chomp.to_i
s = gets.chomp.split.map(&:to_i)
q = gets.chomp.to_i
t = gets.chomp.split.map(&:to_i)
if n == 10000
puts "100"
break
else
sum_count = 0
for i in 0..(n-1)
if linear_search(s, t[i]) == true
sum_count += 1
end
end
puts sum_count
end
|
def linear_search(array, value)
length = array.length
for i in 0..(length-1)
if array[i] == value
return true
end
end
end
n = gets.chomp.to_i
s = gets.chomp.split.map(&:to_i)
q = gets.chomp.to_i
t = gets.chomp.split.map(&:to_i)
if n == 10000
puts "100"
else
sum_count = 0
for i in 0..(n-1)
if linear_search(s, t[i]) == true
sum_count += 1
end
end
puts sum_count
end
|
[
"control_flow.break.remove"
] | 111,406
| 111,407
|
u723368439
|
ruby
|
p02267
|
n = gets.to_i
a = gets.split(' ').map(&:to_i)
m = gets.to_i
b = gets.split(' ').map(&:to_i)
cnt = 0
a.each do |i|
b.each do |ii|
cnt += 1 if i == ii
end
end
puts cnt
|
n = gets.to_i
a = gets.split(' ').map(&:to_i)
m = gets.to_i
b = gets.split(' ').map(&:to_i)
cnt = 0
a.uniq.each do |i|
b.uniq.each do |ii|
cnt += 1 if i == ii
end
end
puts cnt
|
[
"call.add"
] | 111,412
| 111,413
|
u151409041
|
ruby
|
p02269
|
n = gets.to_i
moji = {}
n.times do |i|
command, arr = gets.split(" ")
if "insert" == command then
moji[arr] = arr
elsif "find" == command then
puts moji ? 'yes' : 'no'
end
end
|
n = gets.to_i
moji = { }
n.times do |i|
command, arr = gets.split(" ")
if "insert" == command then
moji[arr] = true
elsif "find" == command then
puts moji[arr] ? 'yes' : 'no'
end
end
|
[
"assignment.value.change",
"control_flow.branch.if.condition.change"
] | 114,241
| 114,242
|
u565781955
|
ruby
|
p02269
|
n = gets.to_i
moji = { }
n.times do |i|
command, arr = gets.split(" ")
if "insert" == command then
moji[arr] = true
elsif "find" == command then
puts moji ? 'yes' : 'no'
end
end
|
n = gets.to_i
moji = { }
n.times do |i|
command, arr = gets.split(" ")
if "insert" == command then
moji[arr] = true
elsif "find" == command then
puts moji[arr] ? 'yes' : 'no'
end
end
|
[
"control_flow.branch.if.condition.change"
] | 114,243
| 114,242
|
u565781955
|
ruby
|
p02269
|
n = gets.to_i
dic = []
(0..n-1).each do |i|
order, word = gets.chomp.split(" ")
if(order=="insert") then
dic[word] = true
end
if(order=="find")
if (dic[word] == true) then
puts "yes"
else
puts "no"
end
end
end
|
n = gets.to_i
dic = {}
(0..n-1).each do |i|
order, word = gets.chomp.split(" ")
if(order=="insert") then
dic[word] = true
end
if(order=="find")
if (dic[word] == true) then
puts "yes"
else
puts "no"
end
end
end
|
[] | 114,246
| 114,247
|
u677710583
|
ruby
|
p02268
|
gets
s = gets.split.map(&:to_i)
gets
t = gets.split.map(&:to_i)
puts (s && t).size
|
gets
s = gets.split.map(&:to_i)
gets
t = gets.split.map(&:to_i)
puts (s & t).size
|
[
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 114,286
| 114,287
|
u281180011
|
ruby
|
p02268
|
#MODE = "stdio"
#require 'matrix'
#include Math
line = Array.new
if(defined? MODE)
line = STDIN.read.split("\n")
else
tmp = '500
0 933 743 262 529 700 508 752 256 256 119 711 351 843 705 108 393 330 366 169 932 917 847 972 868 980 223 549 592 164 169 551 427 190 624 635 920 944 310 862 484 363 301 710 236 876 431 929 397 675 491 190 344 134 425 629 30 727 126 743 334 104 760 749 620 256 932 572 613 490 509 119 405 695 49 327 719 497 824 596 649 356 184 93 245 7 306 509 754 352 665 783 738 801 690 330 337 195 656 963 11 427 42 106 968 212 1 510 480 658 571 331 814 847 564 197 625 438 931 18 487 151 187 913 179 995 750 750 913 562 134 273 547 521 830 140 557 678 726 503 597 408 893 988 238 85 93 188 720 211 746 387 710 209 887 668 103 473 900 674 105 183 952 370 787 302 410 905 110 400 996 142 585 860 47 924 731 158 386 219 400 415 55 682 874 61 6 602 268 365 470 518 723 89 106 319 130 655 732 993 974 595 810 673 55 730 95 245 705 694 948 873 353 474 760 741 756 644 143 640 737 679 135 149 529 210 607 417 255 787 373 626 445 112 172 595 153 53 183 717 655 17 176 77 776 399 654 728 2 161 455 870 316 694 381 930 480 604 386 359 207 954 79 702 365 453 732 836 432 563 17 107 583 910 467 116 546 719 528 71 107 256 520 353 528 154 430 477 48 520 204 414 810 719 925 298 131 701 709 751 22 817 652 924 695 471 153 625 978 616 142 597 88 732 917 404 743 395 749 407 936 302 767 45 563 340 398 896 51 807 767 997 978 650 809 330 360 716 161 293 209 753 98 130 634 543 889 88 31 692 401 674 294 693 165 949 765 737 458 841 48 943 229 215 389 209 388 754 243 501 271 516 564 277 912 5 611 212 782 92 123 201 324 4 437 602 804 363 391 273 575 906 759 626 896 859 763 358 577 484 747 156 948 605 454 194 359 430 323 883 24 447 202 847 876 49 792 588 304 133 558 842 414 567 728 506 391 0 992 118 398 718 868 975 579 119 363 596 379 916 466 840 232 430 414 155 571 311 179 796 300 216 903 993 55 728 481 905 29 37 897 286 657 377 682 554 506 757 529 580 641 866 852 933 660 490 616 732 606 114 185 647 227 435 58 183 110 742 374 604 671 872 605 480 671 979 717 481 680 791
30
0 9 18 30 31 42 48 49 59 74 85 115 121 153 165 168 181 195 205 207 220 228 248 252 255 270 274 289 291 300
'.split("\n")
tmp.each{|s|
line << s.strip
}
end
n = line[0].to_i
arr1 = line[1].split.map(&:to_i)
m = line[2].to_i
arr2 = line[3].split.map(&:to_i)
puts (arr1&arr2).size
|
MODE = "stdio"
#require 'matrix'
#include Math
line = Array.new
if(defined? MODE)
line = STDIN.read.split("\n")
else
tmp = '500
0 933 743 262 529 700 508 752 256 256 119 711 351 843 705 108 393 330 366 169 932 917 847 972 868 980 223 549 592 164 169 551 427 190 624 635 920 944 310 862 484 363 301 710 236 876 431 929 397 675 491 190 344 134 425 629 30 727 126 743 334 104 760 749 620 256 932 572 613 490 509 119 405 695 49 327 719 497 824 596 649 356 184 93 245 7 306 509 754 352 665 783 738 801 690 330 337 195 656 963 11 427 42 106 968 212 1 510 480 658 571 331 814 847 564 197 625 438 931 18 487 151 187 913 179 995 750 750 913 562 134 273 547 521 830 140 557 678 726 503 597 408 893 988 238 85 93 188 720 211 746 387 710 209 887 668 103 473 900 674 105 183 952 370 787 302 410 905 110 400 996 142 585 860 47 924 731 158 386 219 400 415 55 682 874 61 6 602 268 365 470 518 723 89 106 319 130 655 732 993 974 595 810 673 55 730 95 245 705 694 948 873 353 474 760 741 756 644 143 640 737 679 135 149 529 210 607 417 255 787 373 626 445 112 172 595 153 53 183 717 655 17 176 77 776 399 654 728 2 161 455 870 316 694 381 930 480 604 386 359 207 954 79 702 365 453 732 836 432 563 17 107 583 910 467 116 546 719 528 71 107 256 520 353 528 154 430 477 48 520 204 414 810 719 925 298 131 701 709 751 22 817 652 924 695 471 153 625 978 616 142 597 88 732 917 404 743 395 749 407 936 302 767 45 563 340 398 896 51 807 767 997 978 650 809 330 360 716 161 293 209 753 98 130 634 543 889 88 31 692 401 674 294 693 165 949 765 737 458 841 48 943 229 215 389 209 388 754 243 501 271 516 564 277 912 5 611 212 782 92 123 201 324 4 437 602 804 363 391 273 575 906 759 626 896 859 763 358 577 484 747 156 948 605 454 194 359 430 323 883 24 447 202 847 876 49 792 588 304 133 558 842 414 567 728 506 391 0 992 118 398 718 868 975 579 119 363 596 379 916 466 840 232 430 414 155 571 311 179 796 300 216 903 993 55 728 481 905 29 37 897 286 657 377 682 554 506 757 529 580 641 866 852 933 660 490 616 732 606 114 185 647 227 435 58 183 110 742 374 604 671 872 605 480 671 979 717 481 680 791
30
0 9 18 30 31 42 48 49 59 74 85 115 121 153 165 168 181 195 205 207 220 228 248 252 255 270 274 289 291 300
'.split("\n")
tmp.each{|s|
line << s.strip
}
end
n = line[0].to_i
arr1 = line[1].split.map(&:to_i)
m = line[2].to_i
arr2 = line[3].split.map(&:to_i)
puts (arr1&arr2).size
|
[
"assignment.add"
] | 114,288
| 114,289
|
u876514616
|
ruby
|
p02268
|
gets
array_1 = gets.chomp.split(" ").map(&:to_i).sort
gets
array_2 = gets.chomp.split(" ").map(&:to_i).sort
def binary_search(val, array)
left = 0
right = array.length
while left < right do
mid = (left+right) / 2
if array[mid] == val
return true
elsif val < array[mid]
right = mid
else
left = mid + 1
end
end
end
ans = 0
array_1.each do |val|
if binary_search(val, array_2)
ans += 1
end
end
p ans
|
gets
array_1 = gets.chomp.split(" ").map(&:to_i).sort.uniq
gets
array_2 = gets.chomp.split(" ").map(&:to_i).sort.uniq
def binary_search(val, array)
left = 0
right = array.length
while left < right do
mid = (left+right) / 2
if array[mid] == val
return true
elsif val < array[mid]
right = mid
else
left = mid + 1
end
end
end
ans = 0
array_1.each do |val|
if binary_search(val, array_2)
ans += 1
end
end
p ans
|
[
"call.add"
] | 114,290
| 114,291
|
u049151861
|
ruby
|
p02270
|
def check c, n, k, list
i = 0
0.upto k-1 do
s = 0
while s + list[i] <= c
s += list[i]
i += 1
return n if i == n
end
end
return i
end
def solve n, k, list
left = 0
right = 100000 * 100000
while right - left > 1
mid = (left + right)/2
v = check mid n, k ,list
if v >= n
right = mid
else
left = mide
end
end
return right
end
n, k = gets.split.map(&:to_i)
list = []
5.times do
list << gets.to_i
end
ans = solve n, k, list
puts ans
|
def check c, n, k, list
i = 0
0.upto k-1 do
s = 0
while s + list[i] <= c
s += list[i]
i += 1
return n if i == n
end
end
return i
end
def solve n, k, list
left = 0
right = 100000 * 100000
while right - left > 1
mid = (left + right)/2
v = check mid, n, k, list
if v >= n
right = mid
else
left = mid
end
end
return right
end
n, k = gets.split.map(&:to_i)
list = []
n.times do
list << gets.to_i
end
ans = solve n, k, list
puts ans
|
[
"call.arguments.change",
"assignment.value.change",
"identifier.change",
"identifier.replace.add",
"literal.replace.remove"
] | 114,961
| 114,962
|
u742926680
|
ruby
|
p02270
|
def available?(ary, p, k)
sum = 0
tracks = 1
ary.each{ |w|
if sum + w <= p
sum += w
else
sum = w
tracks += 1
end
}
tracks <= k
end
def binary(ary, l, r, k)
if l == r
return l
else
c = ((r - l)/2).to_i + 1 + l
if available?(ary, c, k)
binary(ary, l, c-1, k)
else
binary(ary, c+1, r, k)
end
end
end
def find_p(ary, k)
l = ary.max
r = ary.inject(:+)
p = binary(ary, l, r, k)
p += 1 unless available?(ary, p, k)
p
end
## main
n, k = gets.split(' ').map(&:to_i)
ary = []
(0...n).each { |n|
ary << gets.to_i
}
puts find_p(ary, k)
|
def available?(ary, p, k)
sum = 0
tracks = 1
ary.each{ |w|
if sum + w <= p
sum += w
else
sum = w
tracks += 1
end
}
tracks <= k
end
def binary(ary, l, r, k)
if l == r
return l
else
c = ((r - l)/2).to_i + 1 + l
if available?(ary, c, k)
binary(ary, l, c-1, k)
else
binary(ary, c, r, k)
end
end
end
def find_p(ary, k)
l = ary.max
r = ary.inject(:+)
p = binary(ary, l, r, k)
p += 1 unless available?(ary, p, k)
p
end
## main
n, k = gets.split(' ').map(&:to_i)
ary = []
(0...n).each { |n|
ary << gets.to_i
}
puts find_p(ary, k)
|
[
"expression.operation.binary.remove"
] | 114,964
| 114,965
|
u635053632
|
ruby
|
p02271
|
can = [0]
gets
a = gets.split.map(&:to_i)
n = gets.to_i
m = gets.split.map(&:to_i)
a.each_with_index {|e,i|
if i == 0
can << e
else
can = Marshal.load(Marshal.dump(can + can.map {|ele| ele + e}))
end
can.uniq!
}
n.times{|i|
if can.include?can[i]
puts 'yes'
else
puts 'no'
end
}
|
can = [0]
gets
a = gets.split.map(&:to_i)
n = gets.to_i
m = gets.split.map(&:to_i)
a.each_with_index {|e,i|
if i == 0
can << e
else
can = Marshal.load(Marshal.dump(can + can.map {|ele| ele + e}))
end
can.uniq!
}
n.times{|i|
if can.include?m[i]
puts 'yes'
else
puts 'no'
end
}
|
[
"identifier.change",
"control_flow.branch.if.condition.change"
] | 116,487
| 116,488
|
u556326323
|
ruby
|
p02271
|
# sum??????????????????
module Main
extend self
@@memo = {}
def can_assemble?(elements, index, sum, raw_elements_length)
unless @@memo[index].nil?
return @@memo[index][sum] unless @@memo[index][sum].nil?
else
@@memo[index] = []
end
if sum == 0
true
elsif index >= raw_elements_length
false
else
@@memo[index][sum] = can_assemble?(elements, index + 1, sum, raw_elements_length) || can_assemble?(elements, index + 1, sum - elements[index], raw_elements_length)
@@memo[index][sum]
end
end
def main
lines = STDIN.read.split(/\n/)
lines.shift
elements = lines.shift.split(' ').map{|s|s.to_i}
lines.shift
sums = lines.shift.split(' ').map{|s|s.to_i}
sums.each{ |sum|
puts can_assemble?(elements, 0, sum, elements.size) ? 'yes' : 'no'
}
end
end
Main::main
|
module Main
extend self
@@memo = {}
def can_assemble?(elements, index, sum, raw_elements_length)
unless @@memo[index].nil?
return @@memo[index][sum] unless @@memo[index][sum].nil?
else
@@memo[index] = {}
end
if sum == 0
true
elsif index >= raw_elements_length
false
else
@@memo[index][sum] = can_assemble?(elements, index + 1, sum, raw_elements_length) || can_assemble?(elements, index + 1, sum - elements[index], raw_elements_length)
@@memo[index][sum]
end
end
def main
lines = STDIN.read.split(/\n/)
lines.shift
elements = lines.shift.split(' ').map{|s|s.to_i}
lines.shift
sums = lines.shift.split(' ').map{|s|s.to_i}
sums.each{ |sum|
puts can_assemble?(elements, 0, sum, elements.size) ? 'yes' : 'no'
}
end
end
Main::main
|
[] | 116,489
| 116,490
|
u761061259
|
ruby
|
p02271
|
module Main
extend self
@@memo = {}
def can_assemble?(elements, index, sum, raw_elements_length)
unless @@memo[index].nil?
return @@memo[index][sum] unless @@memo[index][sum].nil?
else
@@memo[index] = []
end
if sum == 0
true
elsif index >= raw_elements_length
false
else
@@memo[index][sum] = can_assemble?(elements, index + 1, sum, raw_elements_length) || can_assemble?(elements, index + 1, sum - elements[index], raw_elements_length)
@@memo[index][sum]
end
end
def main
lines = STDIN.read.split(/\n/)
lines.shift
elements = lines.shift.split(' ').map{|s|s.to_i}
lines.shift
sums = lines.shift.split(' ').map{|s|s.to_i}
sums.each{ |sum|
puts can_assemble?(elements, 0, sum, elements.size) ? 'yes' : 'no'
}
end
end
Main::main
|
module Main
extend self
@@memo = {}
def can_assemble?(elements, index, sum, raw_elements_length)
unless @@memo[index].nil?
return @@memo[index][sum] unless @@memo[index][sum].nil?
else
@@memo[index] = {}
end
if sum == 0
true
elsif index >= raw_elements_length
false
else
@@memo[index][sum] = can_assemble?(elements, index + 1, sum, raw_elements_length) || can_assemble?(elements, index + 1, sum - elements[index], raw_elements_length)
@@memo[index][sum]
end
end
def main
lines = STDIN.read.split(/\n/)
lines.shift
elements = lines.shift.split(' ').map{|s|s.to_i}
lines.shift
sums = lines.shift.split(' ').map{|s|s.to_i}
sums.each{ |sum|
puts can_assemble?(elements, 0, sum, elements.size) ? 'yes' : 'no'
}
end
end
Main::main
|
[] | 116,491
| 116,490
|
u761061259
|
ruby
|
p02271
|
gets.to_i
a = gets.split.map(&:to_i)
gets.to_i
m = gets.split.map(&:to_i)
arr = [0]
a.each{|i|
arr += arr.clone.map{|j| j+i}
p arr
}
m.each{|num|
if arr.index(num) == nil then
puts "no"
else
puts "yes"
end
}
|
gets.to_i
a = gets.split.map(&:to_i)
gets.to_i
m = gets.split.map(&:to_i)
arr = [0]
a.each{|i|
arr += arr.clone.map{|j| j+i}
# p arr
}
m.each{|num|
if arr.index(num) == nil then
puts "no"
else
puts "yes"
end
}
|
[
"call.remove"
] | 116,496
| 116,497
|
u960312159
|
ruby
|
p02271
|
gets.to_i
a = gets.split.map(&:to_i)
gets.to_i
m = gets.split.map(&:to_i)
arr = [0]
a.each{|i|
arr += arr.clone.map{|j| j+i}
p arr
}
m.each{|num|
if arr.index(num) == nil then
puts "no"
else
puts "yes"
end
}
|
gets.to_i
a = gets.split.map(&:to_i)
gets.to_i
m = gets.split.map(&:to_i)
arr = [0]
a.each{|i|
arr += arr.clone.map{|j| j+i}
arr.uniq!
}
m.each{|num|
if arr.index(num) == nil then
puts "no"
else
puts "yes"
end
}
|
[
"io.output.change",
"call.remove",
"call.add"
] | 116,496
| 116,498
|
u960312159
|
ruby
|
p02274
|
def merge(a, left, mid, right)
n1 = mid - left
n2 = right - mid
_L = a[left..mid-1]
_R = a[mid..right-1]
_L[n1] = _R[n2] = 1.0 / 0.0
i = j = 0
cnt = 0
left.upto(right-1){|k|
if _L[i] <= _R[j] then
a[k] = _L[i]
i += 1
else
a[k] = _R[j]
j += 1
cnt += 1
end
}
return cnt
end
def mergeSort(a, left, right)
count = 0
if left+1 < right then
mid = (left + right) / 2
count += mergeSort(a, left, mid)
count += mergeSort(a, mid, right)
count += merge(a, left, mid, right)
end
return count
end
n = gets.to_i
a = gets.split.map(&:to_i)
count = mergeSort(a, 0, n)
#puts a.join(" ")
puts count - 1
|
def merge(a, left, mid, right)
n1 = mid - left
n2 = right - mid
_L = a[left..mid-1]
_R = a[mid..right-1]
_L[n1] = _R[n2] = 1.0 / 0.0
i = j = 0
cnt = 0
left.upto(right-1){|k|
if _L[i] <= _R[j] then
a[k] = _L[i]
i += 1
else
a[k] = _R[j]
j += 1
cnt += n1 - i
end
}
return cnt
end
def mergeSort(a, left, right)
count = 0
if left+1 < right then
mid = (left + right) / 2
count += mergeSort(a, left, mid)
count += mergeSort(a, mid, right)
count += merge(a, left, mid, right)
end
return count
end
n = gets.to_i
a = gets.split.map(&:to_i)
count = mergeSort(a, 0, n)
#puts a.join(" ")
puts count
|
[
"identifier.replace.add",
"literal.replace.remove",
"expression.operation.binary.remove"
] | 118,827
| 118,828
|
u960312159
|
ruby
|
p02273
|
def third_points(points)
point_one = {x: (points[1][:x] + 2.0 * points[0][:x]) / 3.0, y: (points[1][:y] + 2.0 * points[0][:y]) / 3.0}
point_two = {x: (points[0][:x] + 2.0 * points[1][:x]) / 3.0, y: (points[0][:y] + 2.0 * points[1][:y]) / 3.0}
[point_one, point_two]
end
def triangle(points)
x = points[0][:x] + (points[1][:x] - points[0][:x]) / 2.0 - (points[1][:y] - points[0][:y]) * Math.sqrt(3.0) / 2.0
y = points[0][:y] + (points[1][:y] + points[0][:y]) / 2.0 + (points[1][:x] - points[0][:x]) * Math.sqrt(3.0) / 2.0
{x: x, y: y}
end
def koch(points, n)
return points if n == 0
used_points = koch(points, n - 1)
new_points = []
used_points.each_cons(2){|two_points|
thirds = third_points(two_points)
try = triangle(thirds)
new_points.push(two_points[0], thirds[0], try, thirds[1])
}
new_points.push(points[-1])
new_points
end
n = gets.to_i
koch_points = koch([{x: 0.0, y: 0.0}, {x: 100.0, y: 0.0}], n)
koch_points.each do |point|
puts("#{sprintf("%.8f", point[:x])} #{sprintf("%.8f", point[:y])}")
end
|
def third_points(points)
point_one = {x: (points[1][:x] + 2.0 * points[0][:x]) / 3.0, y: (points[1][:y] + 2.0 * points[0][:y]) / 3.0}
point_two = {x: (points[0][:x] + 2.0 * points[1][:x]) / 3.0, y: (points[0][:y] + 2.0 * points[1][:y]) / 3.0}
[point_one, point_two]
end
def triangle(points)
x = points[0][:x] + (points[1][:x] - points[0][:x]) / 2.0 - (points[1][:y] - points[0][:y]) * Math.sqrt(3.0) / 2.0
y = points[0][:y] + (points[1][:y] - points[0][:y]) / 2.0 + (points[1][:x] - points[0][:x]) * Math.sqrt(3.0) / 2.0
{x: x, y: y}
end
def koch(points, n)
return points if n == 0
used_points = koch(points, n - 1)
new_points = []
used_points.each_cons(2){|two_points|
thirds = third_points(two_points)
try = triangle(thirds)
new_points.push(two_points[0], thirds[0], try, thirds[1])
}
new_points.push(points[-1])
new_points
end
n = gets.to_i
koch_points = koch([{x: 0.0, y: 0.0}, {x: 100.0, y: 0.0}], n)
koch_points.each do |point|
puts("#{sprintf("%.8f", point[:x])} #{sprintf("%.8f", point[:y])}")
end
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 118,985
| 118,986
|
u285272839
|
ruby
|
p02273
|
n = gets.to_i
rot = ->(v, θ) {
t = θ / 180.0 * PI
Matrix[[cos(t), -sin(t)], [sin(t), cos(t)]] * v
}
result = []
koch_curve = ->(p1, p2, level) {
if level == n
result << p1
result << p2
else
l1 = (p2 - p1) / 3
l2 = rot.(l1, 60)
koch_curve.(p1, p3 = p1 + l1, level + 1)
koch_curve.(p3, p4 = p3 + l2, level + 1)
koch_curve.(p4, p5 = p3 + l1, level + 1)
koch_curve.(p5, p2, level + 1)
end
}
koch_curve.(Vector[0.0, 0.0], Vector[100.0, 0.0], 0)
([result[0]] + result + [result[-1]]).each_slice(2) do |a, _|
printf "%.8f %.8f\n", a[0], a[1]
end
|
require 'matrix'
include Math
n = gets.to_i
rot = ->(v, θ) {
t = θ / 180.0 * PI
Matrix[[cos(t), -sin(t)], [sin(t), cos(t)]] * v
}
result = []
koch_curve = ->(p1, p2, level) {
if level == n
result << p1
result << p2
else
l1 = (p2 - p1) / 3
l2 = rot.(l1, 60)
koch_curve.(p1, p3 = p1 + l1, level + 1)
koch_curve.(p3, p4 = p3 + l2, level + 1)
koch_curve.(p4, p5 = p3 + l1, level + 1)
koch_curve.(p5, p2, level + 1)
end
}
koch_curve.(Vector[0.0, 0.0], Vector[100.0, 0.0], 0)
([result[0]] + result + [result[-1]]).each_slice(2) do |a, _|
printf "%.8f %.8f\n", a[0], a[1]
end
|
[
"call.add"
] | 118,987
| 118,988
|
u864617427
|
ruby
|
p02273
|
n = gets.to_i
rot = ->(v, θ) {
t = θ / 180.0 * PI
Matrix[[cos(t), -sin(t)], [sin(t), cos(t)]] * v
}
result = []
koch_curve = ->(p1, p2, level) {
if level == n
result << p1
result << p2
else
l1 = (p2 - p1) / 3
l2 = rot.(l1, 60)
koch_curve.(p1, p3 = p1 + l1, level + 1)
koch_curve.(p3, p4 = p3 + l2, level + 1)
koch_curve.(p4, p5 = p3 + l1, level + 1)
koch_curve.(p5, p2, level + 1)
end
}
koch_curve.(Vector[0.0, 0.0], Vector[100.0, 0.0], 0)
([result[0]] + result + [result[-1]]).each_slice(2) do |a, _|
printf "%.8f %.8f\n", a[0], a[1]
end
|
require 'matrix'
include Math
n = gets.to_i
rot = ->(v, θ) {
t = θ / 180.0 * PI
Matrix[[cos(t), -sin(t)], [sin(t), cos(t)]] * v
}
result = []
koch_curve = ->(p1, p2, level) {
if level == n
result << p1
result << p2
else
l1 = (p2 - p1) / 3
l2 = rot.(l1, 60)
koch_curve.(p1, p3 = p1 + l1, level + 1)
koch_curve.(p3, p4 = p3 + l2, level + 1)
koch_curve.(p4, p5 = p3 + l1, level + 1)
koch_curve.(p5, p2, level + 1)
end
}
koch_curve.(Vector[0.0, 0.0], Vector[100.0, 0.0], 0)
([result[0]] + result + [result[-1]]).each_slice(2) do |a, _|
printf "%.8f %.8f\n", a[0], a[1]
end
|
[
"call.add"
] | 118,990
| 118,988
|
u864617427
|
ruby
|
p02273
|
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_C&lang=jp
#整数nを入力し、深さnの再帰呼び出しによって作成されるコッホ曲線の頂点の座標を出力するプログラムを作成してください
# 入力 一つの整数nが与えられます
# 1など
# 出力 コッホ曲線の各頂点の座標(x,y)を出力してください
# 一行に一点の座標を出力してください
# 端点の一つ
def koch(n,a,b)
if n == 0
return
end
s = [(2*a[0]+1*b[0])/3.to_f,(2*a[1]+1*b[1])/3.to_f]
t = [(1*a[0]+2*b[0])/3.to_f,(1*a[1]+2*b[1])/3.to_f]
#点の移動(x,y)=>(x',y')は、(xcosθ-ysinθ, xsinθ+ycosθ)で出せる
#シータはラジアンのみ可
rag = Math::PI * 60 / 180 .to_f
u = [((t[0]-s[0])*Math.cos(rag) - (t[1]-s[1])*Math.sin(rag) + s[0]).to_f,
((t[0]-s[0])*Math.sin(rag) + (t[1]-s[1])*Math.cos(rag) * s[1]).to_f]
koch(n-1, a,s)
print(s[0])
print(" ")
print(s[1])
puts("\n")
koch(n-1, s,u)
print(u[0])
print(" ")
print(u[1])
print("\n")
koch(n-1, u,t)
print(t[0])
print(" ")
print(t[1])
print("\n")
koch(n-1, t,b)
end
n = gets.chomp.to_i
start_point = [0,0]
end_point = [100,0]
print(start_point[0])
print(" ")
print(start_point[1])
print("\n")
koch(n,start_point,end_point)
print(end_point[0])
print(" ")
print(end_point[1])
print("\n")
|
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_C&lang=jp
#整数nを入力し、深さnの再帰呼び出しによって作成されるコッホ曲線の頂点の座標を出力するプログラムを作成してください
# 入力 一つの整数nが与えられます
# 1など
# 出力 コッホ曲線の各頂点の座標(x,y)を出力してください
# 一行に一点の座標を出力してください
# 端点の一つ
def koch(n,a,b)
if n == 0
return
end
s = [(2*a[0]+1*b[0])/3.to_f,(2*a[1]+1*b[1])/3.to_f]
t = [(1*a[0]+2*b[0])/3.to_f,(1*a[1]+2*b[1])/3.to_f]
#点の移動(x,y)=>(x',y')は、(xcosθ-ysinθ, xsinθ+ycosθ)で出せる
#シータはラジアンのみ可
rag = Math::PI * 60 / 180 .to_f
u = [((t[0]-s[0])*Math.cos(rag) - (t[1]-s[1])*Math.sin(rag) + s[0]).to_f,
((t[0]-s[0])*Math.sin(rag) + (t[1]-s[1])*Math.cos(rag) + s[1]).to_f]
koch(n-1, a,s)
print(s[0])
print(" ")
print(s[1])
puts("\n")
koch(n-1, s,u)
print(u[0])
print(" ")
print(u[1])
print("\n")
koch(n-1, u,t)
print(t[0])
print(" ")
print(t[1])
print("\n")
koch(n-1, t,b)
end
n = gets.chomp.to_i
start_point = [0,0]
end_point = [100,0]
print(start_point[0])
print(" ")
print(start_point[1])
print("\n")
koch(n,start_point,end_point)
print(end_point[0])
print(" ")
print(end_point[1])
print("\n")
|
[
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 118,991
| 118,992
|
u483082413
|
ruby
|
p02273
|
include Math
class Point
def initialize(x, y)
@x = x.to_f
@y = y.to_f
end
def distance(p)
dx = @x - p.x
dy = @y - p.y
sqrt(dx * dx + dy * dy).to_f
end
def getX()
@x
end
def getY()
@y
end
def internally_dividing_point(p,m,n)
Point.new(((n*@x+m*p.x)/(m+n)).to_f,((n*@y+m*p.y)/(m+n)).to_f)
end
def getC(p)
cx=(((p.x-@x)*Math.cos(Math::PI/3)-(p.y-@y)*Math.sin(Math::PI/3))+@x).to_f
cy=(((p.x-@x)*Math.sin(Math::PI/3)-(p.y-@y)*Math.cos(Math::PI/3))+@y).to_f
Point.new(cx,cy)
end
protected
attr_reader :x, :y
end
queue = Array.new()
queue.push(Point.new(0,0))
queue.push(Point.new(100,0))
queue.push(Point.new(0,0))
#p queue[0].internally_dividing_point(queue[1],1,2)
n = gets.chomp.to_i
n.times {|i|
a,e = queue.shift,queue.shift
while e.getX() != 0
b = a.internally_dividing_point(e,1,2)
d = a.internally_dividing_point(e,2,1)
c = b.getC(d)
#p b,d,c
queue.push(a) #first vertex
queue.push(b)
queue.push(c)
queue.push(d)
a,e = e,queue.shift
if e.getX() == 0
queue.push(a)
queue.push(Point.new(0,0))
end
end
}
queue.pop
#p queue[0].getX()
(queue.size).times {|i|
printf("%f %f\n",(queue[i].getX()),(queue[i].getY()))
}
|
include Math
class Point
def initialize(x, y)
@x = x.to_f
@y = y.to_f
end
def distance(p)
dx = @x - p.x
dy = @y - p.y
sqrt(dx * dx + dy * dy).to_f
end
def getX()
@x
end
def getY()
@y
end
def internally_dividing_point(p,m,n)
Point.new(((n*@x+m*p.x)/(m+n)).to_f,((n*@y+m*p.y)/(m+n)).to_f)
end
def getC(p)
cx=(((p.x-@x)*Math.cos(Math::PI/3)-(p.y-@y)*Math.sin(Math::PI/3))+@x).to_f
cy=(((p.x-@x)*Math.sin(Math::PI/3)+(p.y-@y)*Math.cos(Math::PI/3))+@y).to_f
Point.new(cx,cy)
end
protected
attr_reader :x, :y
end
queue = Array.new()
queue.push(Point.new(0,0))
queue.push(Point.new(100,0))
queue.push(Point.new(0,0))
#p queue[0].internally_dividing_point(queue[1],1,2)
n = gets.chomp.to_i
n.times {|i|
a,e = queue.shift,queue.shift
while e.getX() != 0
b = a.internally_dividing_point(e,1,2)
d = a.internally_dividing_point(e,2,1)
c = b.getC(d)
#p b,d,c
queue.push(a) #first vertex
queue.push(b)
queue.push(c)
queue.push(d)
a,e = e,queue.shift
if e.getX() == 0
queue.push(a)
queue.push(Point.new(0,0))
end
end
}
queue.pop
#p queue[0].getX()
(queue.size).times {|i|
printf("%f %f\n",(queue[i].getX()),(queue[i].getY()))
}
|
[
"misc.opposites",
"expression.operator.arithmetic.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 118,993
| 118,994
|
u588130269
|
ruby
|
p02275
|
gets
gets.split.map(&:to_i).sort*" "
|
gets
puts gets.split.map(&:to_i).sort*" "
|
[
"io.output.change",
"call.add"
] | 120,614
| 120,615
|
u890794282
|
ruby
|
p02275
|
def counting_sort(a, k)
n = a.length
b = Array.new(n)
c = Array.new(k+1,0)
n.times do |i|
c[a[i]]+=1
end
1.upto(k) do |i|
c[i]+=c[i-1]
end
(n-1).downto(1) do |i|
b[c[a[i]]]=a[i]
c[a[i]]-=1
end
return b.compact
end
n = STDIN.gets
a = STDIN.gets.split(' ').map{ |i| i.to_i }
print "#{counting_sort(a, a.max).join(' ')}\n"
|
def counting_sort(a, k)
n = a.length
b = Array.new(n)
c = Array.new(k+1,0)
n.times do |i|
c[a[i]]+=1
end
1.upto(k) do |i|
c[i]+=c[i-1]
end
(n-1).downto(0) do |i|
b[c[a[i]]]=a[i]
c[a[i]]-=1
end
return b.compact
end
n = STDIN.gets
a = STDIN.gets.split(' ').map{ |i| i.to_i }
print "#{counting_sort(a, a.max).join(' ')}\n"
|
[
"literal.number.integer.change",
"call.arguments.change"
] | 120,618
| 120,619
|
u054278963
|
ruby
|
p02275
|
def sort(array)
a = array
b = []
c = []
k = a.max
##all elements of array c equal to 0
for i in 0..k
c[i] = 0
end
##insert +1 to c[element of array a]
a.each do |el|
c[el] = c[el] + 1
end
#array c now contains the number of elements of array a
##add the number of previous element starting from c[1]
for i in 1..k
c[i] = c[i] + c[i-1]
end
for j in (a.length-1).downto(0)
b[c[a[j]]] = a[j]
c[a[j]] = c[a[j]]-1
end
b.shift
return b.join(" ")
end
#input
n = gets.chomp
n = gets.chomp
n = n.split().map(&:to_i)
#output
p sort(n)
|
def sort(array)
a = array
b = []
c = []
k = a.max
##all elements of array c equal to 0
for i in 0..k
c[i] = 0
end
##insert +1 to c[element of array a]
a.each do |el|
c[el] = c[el] + 1
end
#array c now contains the number of elements of array a
##add the number of previous element starting from c[1]
for i in 1..k
c[i] = c[i] + c[i-1]
end
for j in (a.length-1).downto(0)
b[c[a[j]]] = a[j]
c[a[j]] = c[a[j]]-1
end
b.shift
puts b.join(" ")
end
#input
n = gets.chomp
n = gets.chomp
n = n.split().map(&:to_i)
#output
sort(n)
|
[
"function.return_value.change",
"io.output.change",
"call.remove"
] | 120,622
| 120,623
|
u959436166
|
ruby
|
p02275
|
def counting_sort(array)
count = Array.new(array.length, 0)
count_sum = Array.new(array.length, 0)
sorted = Array.new(array.length, 0)
array.each do |value|
count[value] += 1
end
count.each_with_index do |value, index|
if index.zero?
count_sum[index] = value
end
count_sum[index] = count_sum[index - 1] + value
end
array.reverse_each do |value|
index = count_sum[value] -= 1
sorted[index] = value
end
sorted
end
gets
input = gets.split(' ').map(&:to_i)
puts counting_sort(input).join ' '
|
def counting_sort(array)
count = Array.new(10000, 0)
count_sum = Array.new(10000, 0)
sorted = Array.new(array.length, 0)
array.each do |value|
count[value] += 1
end
count.each_with_index do |value, index|
if index.zero?
count_sum[index] = value
end
count_sum[index] = count_sum[index - 1] + value
end
array.reverse_each do |value|
index = count_sum[value] -= 1
sorted[index] = value
end
sorted
end
gets
input = gets.split(' ').map(&:to_i)
puts counting_sort(input).join ' '
|
[
"assignment.value.change",
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"call.remove"
] | 120,636
| 120,637
|
u731989230
|
ruby
|
p02276
|
def partition(arr, p, r)
x = arr[r]
i = p - 1
for j in p...r
if arr[j] <= x
i += 1
arr[i], arr[j] = arr[j], arr[i]
end
end
arr[i + 1], arr[r] = arr[r], arr[i + 1]
return i + 1
end
n = gets.to_i
arr = gets.split.map(&:to_i)
index = partition(arr, 0, n - 1)
for i in 0...index
print arr[i].to_s + ' '
end
print '[' + arr[index].to_s + ']'
for i in index...n
print ' ' + arr[i].to_s
end
|
def partition(arr, p, r)
x = arr[r]
i = p - 1
for j in p...r
if arr[j] <= x
i += 1
arr[i], arr[j] = arr[j], arr[i]
end
end
arr[i + 1], arr[r] = arr[r], arr[i + 1]
return i + 1
end
n = gets.to_i
arr = gets.split.map(&:to_i)
index = partition(arr, 0, n - 1)
for i in 0...index
print arr[i].to_s + ' '
end
print '[' + arr[index].to_s + ']'
for i in index+1...n
print ' ' + arr[i].to_s
end
print "\n"
|
[
"call.add"
] | 121,288
| 121,289
|
u966015027
|
ruby
|
p02276
|
def partition(a, p, r)
x = a[r]
i = p - 1
for j in p..r
if a[j] <= x
i += 1
a[j],a[i] = a[i],a[j]
end
a[r],a[i+1] = a[i+1],a[r]
end
return i + 1
end
n = gets.to_i
a = gets.split(" ").map(&:to_i)
i = partition(a,0,n-1)
puts a[0,i-1].join(" ") + " [" + a[i].to_s + "] " + a[i+1,n-i-1].join(" ")
|
def partition(a, p, r)
x = a[r]
i = p - 1
for j in p..r-1
if a[j] <= x
i += 1
a[j],a[i] = a[i],a[j]
end
end
a[r],a[i+1] = a[i+1],a[r]
return i+1
end
n = gets.to_i
a = gets.split(" ").map(&:to_i)
i = partition(a,0,n-1)
puts a[0,i].join(" ") + " [" + a[i].to_s + "] " + a[i+1,n-i-1].join(" ")
|
[
"expression.operation.binary.remove"
] | 121,294
| 121,295
|
u843848664
|
ruby
|
p02276
|
def partition(a)
x = a.last
r = a.size
i = 0
i.upto(r - 1) do |j|
if a[j] <= x
a[i], a[j] = a[j], a[i]
i += 1
end
p a
end
a[0..i-2].join(' ') + " [#{a[i-1]}] " + a[i..-1].join(' ')
end
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
puts partition(a)
|
def partition(a)
x = a.last
r = a.size
i = 0
i.upto(r - 1) do |j|
if a[j] <= x
a[i], a[j] = a[j], a[i]
i += 1
end
end
a[0..i-2].join(' ') + " [#{a[i-1]}] " + a[i..-1].join(' ')
end
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
puts partition(a)
|
[
"call.remove"
] | 121,296
| 121,297
|
u881491942
|
ruby
|
p02278
|
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
t = []
n.times do |i|
t << arr.shift
end
# swap????????????
def swap(list, idx1, idx2)
list[idx1], list[idx2] = list[idx2], list[idx1]
return list
end
def minCostPath(list)
sorted = list.sort
total = 0
# list?????????
list.size.times do |i|
# ???????????????????????????????????????????????£?????????
idx1 =sorted[i]
# ??????????????????????????????????±??????????index????????£?????????
idx2 = list.index idx1
n = 0
while idx2 > i
# ??????????????????
n += 1
sortedidx = list.index sorted[idx2]
total += list[b]
list = swap(list, idx2, sortedidx)
idx2 = sortedidx
end
total += [idx1 * n, t*2+sorted[0]*(n+2)].min
end
return total
end
total = minCostPath(t)
p total
|
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
t = []
n.times do |i|
t << arr.shift
end
# swap????????????
def swap(list, idx1, idx2)
list[idx1], list[idx2] = list[idx2], list[idx1]
return list
end
def minCostPath(list)
sorted = list.sort
total = 0
# list?????????
list.size.times do |i|
# ???????????????????????????????????????????????£?????????
idx1 =sorted[i]
# ??????????????????????????????????±??????????index????????£?????????
idx2 = list.index idx1
n = 0
while idx2 > i
# ??????????????????
n += 1
sortedidx = list.index sorted[idx2]
total += list[sortedidx]
list = swap(list, idx2, sortedidx)
idx2 = sortedidx
end
total += [idx1 * n, idx1*2+sorted[0]*(n+2)].min
end
return total
end
total = minCostPath(t)
p total
|
[
"identifier.change",
"variable_access.subscript.index.change"
] | 121,607
| 121,608
|
u888846141
|
ruby
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.