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
9 values
p00047
def ball(c1, c2, b) case b when c1 return c2 when c2 return c1 else return b end end b = "A" while line = gets cup1, cup2 = line.chomp.split(",") p b = ball(cup1, cup2, b) end puts b
def ball(c1, c2, b) case b when c1 return c2 when c2 return c1 else return b end end b = "A" while line = gets cup1, cup2 = line.chomp.split(",") b = ball(cup1, cup2, b) end puts b
[ "io.output.change", "call.remove" ]
25,971
25,972
u814658648
ruby
p00049
#!/usr/bin/ruby # -*- coding: utf-8 -*- a = 0; b = 0; o = 0; ab = 0; while s = gets btype = (s.chomp.split(','))[1] if btype == "A" a += 1 elsif btype == "B" b += 1 elsif btype == "O" o += 1 else ab += 1 end end puts a puts b puts o puts ab
#!/usr/bin/ruby # -*- coding: utf-8 -*- a = 0; b = 0; o = 0; ab = 0; while s = gets btype = (s.chomp.split(','))[1] if btype == "A" a += 1 elsif btype == "B" b += 1 elsif btype == "O" o += 1 else ab += 1 end end puts a puts b puts ab puts o
[ "call.remove", "call.add" ]
26,059
26,060
u233891002
ruby
p00049
r = {"A" => 0, "B" => 0, "AB" => 0, "O" => 0} while a = gets.chomp r[a.split(",")[1]] += 1 end r.each_value{ |i| puts i }
r = {"A" => 0, "B" => 0, "AB" => 0, "O" => 0} begin while a = gets.chomp r[a.split(",")[1]] += 1 end rescue end r.each_value{ |i| puts i }
[]
26,061
26,062
u708862509
ruby
p00049
r = {"A" => 0, "B" => 0, "AB" => 0, "O" => 0} while a = gets.chomp r[a.split(",")[1]] += 1 end r.each_value{ |i| puts i }
r = {"A" => 0, "B" => 0, "AB" => 0, "O" => 0} while a = gets r[a.chomp.split(",")[1]] += 1 end r.each_value{ |i| puts i }
[ "call.remove", "call.add" ]
26,061
26,063
u708862509
ruby
p00048
classes = %w(light_fly fly bantam feather light light_welter welter light_middle mddle light_heavy heavy) upper_bound = [48,51,54,57,60,64,69,75,81,91, Float::INFINITY] puts $<.map {|s| classes[upper_bound.index{|ub| s.to_f <= ub}].sub(?_, ' ') }
classes = %w(light_fly fly bantam feather light light_welter welter light_middle middle light_heavy heavy) upper_bound = [48,51,54,57,60,64,69,75,81,91, Float::INFINITY] puts $<.map {|s| classes[upper_bound.index{|ub| s.to_f <= ub}].sub(?_, ' ') }
[ "literal.string.change", "assignment.value.change" ]
26,115
26,116
u797180951
ruby
p00048
def result(w) r = "" if w <= 48.0 then r = "light fly" elsif w <= 51.0 then r = "fly" elsif w <= 54.0 then r = "bandam" elsif w <= 57.0 then r = "feather" elsif w <= 60.0 then r = "light" elsif w <= 64.0 then r = "light welter" elsif w <= 69.0 then r = "welter" elsif w <= 75.0 then r = "light middle" elsif w <= 81.0 then r = "middle" elsif w <= 91.0 then r = "light heavy" else r = "heavy" end r end while line = gets do w = line.to_f puts result(w) end
def result(w) r = "" if w <= 48.0 then r = "light fly" elsif w <= 51.0 then r = "fly" elsif w <= 54.0 then r = "bantam" elsif w <= 57.0 then r = "feather" elsif w <= 60.0 then r = "light" elsif w <= 64.0 then r = "light welter" elsif w <= 69.0 then r = "welter" elsif w <= 75.0 then r = "light middle" elsif w <= 81.0 then r = "middle" elsif w <= 91.0 then r = "light heavy" else r = "heavy" end r end while line = gets do w = line.chop.to_f puts result(w) end
[ "literal.string.change", "assignment.value.change", "call.add" ]
26,117
26,118
u480817624
ruby
p00048
def result(w) r = "" if w <= 48.0 then r = "light fly" elsif w <= 51.0 then r = "fly" elsif w <= 54.0 then r = "bandam" elsif w <= 57.0 then r = "feather" elsif w <= 60.0 then r = "light" elsif w <= 64.0 then r = "light welter" elsif w <= 69.0 then r = "welter" elsif w <= 75.0 then r = "light middle" elsif w <= 81.0 then r = "middle" elsif w <= 91.0 then r = "light heavy" else r = "heavy" end r end while line = gets do w = line.chop.to_f puts result(w) end
def result(w) r = "" if w <= 48.0 then r = "light fly" elsif w <= 51.0 then r = "fly" elsif w <= 54.0 then r = "bantam" elsif w <= 57.0 then r = "feather" elsif w <= 60.0 then r = "light" elsif w <= 64.0 then r = "light welter" elsif w <= 69.0 then r = "welter" elsif w <= 75.0 then r = "light middle" elsif w <= 81.0 then r = "middle" elsif w <= 91.0 then r = "light heavy" else r = "heavy" end r end while line = gets do w = line.chop.to_f puts result(w) end
[ "literal.string.change", "assignment.value.change" ]
26,119
26,118
u480817624
ruby
p00048
C = { 48 => 'light fly', 51 => 'fly', 54 => 'bandam', 57 => 'feather', 60 => 'light', 64 => 'light welter', 69 => 'welter', 75 => 'light middle', 81 => 'middle', 91 => 'light heavy', 9999 => 'heavy' } while s = gets w = s.to_f n = nil C.sort.each { |k, v| if w <= k n = v break end } n = C[9999] if n.nil? puts n end
C = { 48 => 'light fly', 51 => 'fly', 54 => 'bantam', 57 => 'feather', 60 => 'light', 64 => 'light welter', 69 => 'welter', 75 => 'light middle', 81 => 'middle', 91 => 'light heavy', 9999 => 'heavy' } while s = gets w = s.to_f n = nil C.sort.each { |k, v| if w <= k n = v break end } n = C[9999] if n.nil? puts n end
[ "literal.string.change", "assignment.value.change" ]
26,120
26,121
u854447110
ruby
p00050
ap, pa, a, p = 'apple', 'pech', 'a' * 10000, 'p' * 10000 puts gets.sub(ap, a).sub(pa, p).sub(a, pa).sub(p, ap)
ap, pa, a, p = 'apple', 'peach', 'a' * 10000, 'p' * 10000 puts gets.gsub(ap, a).gsub(pa, p).gsub(a, pa).gsub(p, ap)
[ "literal.string.change", "assignment.value.change", "identifier.change", "call.arguments.change", "io.output.change" ]
26,712
26,713
u621997536
ruby
p00050
text = gets.chomp offset = 0 loop do a = text.index("apple", offset) b = text.index("peach", offset) if a && b if a < b offset = a + 1 text[a,5] = "peach" else offset = b + 1 text[a,5] = "apple" end elsif a text[a,5] = "peach" offset = a + 1 elsif b text[b,5] = "apple" offset = b + 1 else break end end puts text
text = gets.chomp offset = 0 loop do a = text.index("apple", offset) b = text.index("peach", offset) if a && b if a < b offset = a + 1 text[a,5] = "peach" else offset = b + 1 text[b,5] = "apple" end elsif a text[a,5] = "peach" offset = a + 1 elsif b text[b,5] = "apple" offset = b + 1 else break end end puts text
[ "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change" ]
26,719
26,720
u960312159
ruby
p00051
for i in 1..gets.to_i s=gets.split(//).map(&:to_i) min=s.sort! max=s.reverse puts max.join.to_i-min.join.to_i end
for i in 1..gets.to_i s=gets.chomp.split(//).map(&:to_i) min=s.sort! max=s.reverse puts max.join.to_i-min.join.to_i end
[ "call.add" ]
26,836
26,837
u287407095
ruby
p00055
while gets sum = $_.to_f 9.times do |i| i % 2 == 0 ? a *= 2 : a /= 3 sum += a end puts sum end
while gets a, sum = $_.to_f sum = a 9.times do |i| i % 2 == 0 ? a *= 2 : a /= 3 sum += a end puts sum end
[ "assignment.add" ]
27,065
27,066
u814658648
ruby
p00055
while gets sum = $_.to_f 9.times do |i| i % 2 == 0 ? a *= 2 : a /= 3 sum += a end puts sum end
while gets sum = a = $_.to_f 9.times do |i| i % 2 == 0 ? a *= 2 : a /= 3 sum += a end puts sum end
[ "assignment.add" ]
27,065
27,067
u814658648
ruby
p00060
cards = Array.new(11,1) a,b,c = gets.split.map &:to_i cards[a] = 0 cards[b] = 0 cards[c] = 0 r = 20 - a - b count = 0 r = 10 if r > 10 r.times { |i| count += cards[i + 1] } puts ["NO", "YES"][count/4]
while t = gets cards = Array.new(11,1) a,b,c = t.split.map &:to_i cards[a] = 0 cards[b] = 0 cards[c] = 0 r = 20 - a - b count = 0 r = 10 if r > 10 r.times { |i| count += cards[i + 1] } puts ["NO", "YES"][count/4] end
[ "assignment.value.change", "identifier.change" ]
27,408
27,409
u708862509
ruby
p00058
#!ruby -n l=$_.split.map(&:to_f) puts ((l[3]-l[1])*(l[7]-l[5])+(l[2]-l[0])*(l[6]-l[4])<1e-8)? 'YES': 'NO'
#!ruby -n l=$_.split.map(&:to_f) puts ((l[3]-l[1])*(l[7]-l[5])+(l[2]-l[0])*(l[6]-l[4])).abs<1e-12? 'YES': 'NO'
[ "expression.operation.binary.remove", "control_flow.branch.if.condition.change" ]
27,613
27,614
u316203371
ruby
p00058
#!ruby -n l=$_.split.map(&:to_f) puts ((l[3]-l[1])*(l[7]-l[5])+(l[2]-l[0])*(l[6]-l[4])<1e-10)? 'YES': 'NO'
#!ruby -n l=$_.split.map(&:to_f) puts ((l[3]-l[1])*(l[7]-l[5])+(l[2]-l[0])*(l[6]-l[4])).abs<1e-12? 'YES': 'NO'
[ "expression.operation.binary.remove", "control_flow.branch.if.condition.change" ]
27,615
27,614
u316203371
ruby
p00058
while str = STDIN.gets if str == -1 then break end a = str.split(' '); eps = 1e-11; for i in 0...8 do a[i] = a[i].to_i end if ((a[0]-a[2])*(a[4]-a[6])+(a[1]-a[3])*(a[5]-a[7])).abs <= eps then puts "YES\n" else puts "NO\n" end end
while str = STDIN.gets if str == -1 then break end a = str.split(' '); eps = 1e-12; for i in 0...8 do a[i] = a[i].to_f end if ((a[0]-a[2])*(a[4]-a[6])+(a[1]-a[3])*(a[5]-a[7])).abs <= eps then puts "YES\n" else puts "NO\n" end end
[ "literal.number.float.change", "assignment.value.change", "call.function.change", "type_conversion.to_float.change", "type_conversion.to_number.change" ]
27,619
27,620
u904101743
ruby
p00058
while str = STDIN.gets if str == -1 then break end a = str.split(' '); eps = 1e-12; for i in 0...8 do a[i] = a[i].to_i end if ((a[0]-a[2])*(a[4]-a[6])+(a[1]-a[3])*(a[5]-a[7])).abs <= eps then puts "YES\n" else puts "NO\n" end end
while str = STDIN.gets if str == -1 then break end a = str.split(' '); eps = 1e-12; for i in 0...8 do a[i] = a[i].to_f end if ((a[0]-a[2])*(a[4]-a[6])+(a[1]-a[3])*(a[5]-a[7])).abs <= eps then puts "YES\n" else puts "NO\n" end end
[ "call.function.change", "type_conversion.to_float.change", "type_conversion.to_number.change" ]
27,621
27,620
u904101743
ruby
p00053
max=110000 array=[*2..max] 2.upto(Math.sqrt(max)) do |num1| array.reject! do |num2| (num2%num1==0)&&(num2>num1) end end p array.size while gets break if $_.to_i==0 x=0 for i in 0...$_.to_i x+=array[i] end puts x end
max=110000 array=[*2..max] 2.upto(Math.sqrt(max)) do |num1| array.reject! do |num2| (num2%num1==0)&&(num2>num1) end end while gets break if $_.to_i==0 x=0 for i in 0...$_.to_i x+=array[i] end puts x end
[ "call.remove" ]
27,917
27,916
u287407095
ruby
p00053
max = 105000 sn = max.to_f**0.5.ceil is_prime = [false, false] + [true]*(max-1) (2..sn).each do |i| next unless is_prime[i] (i*i).step(max, i) do |j| is_prime[j] = false end end prime_list = (2..max).to_a.select{ |i| is_prime[i] } puts prime_list.size while n = gets.to_i do break if n == 0 puts prime_list[0..(n-1)].inject(:+) end
max = 105000 sn = max.to_f**0.5.ceil is_prime = [false, false] + [true]*(max-1) (2..sn).each do |i| next unless is_prime[i] (i*i).step(max, i) do |j| is_prime[j] = false end end prime_list = (2..max).to_a.select{ |i| is_prime[i] } while n = gets.to_i do break if n == 0 puts prime_list[0..(n-1)].inject(:+) end
[ "call.remove" ]
27,921
27,922
u708217907
ruby
p00063
s = 0 while a = gets.chop f = 1 a.size.times{|i| f = 0 if a[i] != a[~i] } s += f end p s
s = 0 while a = gets a.chop! f = 1 a.size.times{|i| f = 0 if a[i] != a[~i] } s += f end p s
[ "call.add", "identifier.change" ]
28,041
28,042
u708862509
ruby
p00056
primes = Array.new(1_000_000, true) primes[0, 2] = [false, false] 2.upto(999_999){|x| if primes[x] m = 2 while x * m <= 999_999 primes[x * m] = false m += 1 end end } while true n = gets.to_i break if n == 0 sum = 0 3.upto(n/2){|x| sum += 1 if primes[x] && primes[n - x]} puts sum end
primes = Array.new(50000, true) primes[0, 2] = [false, false] 2.upto(50000 - 1){|x| if primes[x] m = 2 while x * m <= 999_999 primes[x * m] = false m += 1 end end } while true n = gets.to_i break if n == 0 sum = 0 2.upto(n/2){|x| sum += 1 if primes[x] && primes[n - x]} puts sum end
[ "literal.number.integer.change", "assignment.value.change", "call.arguments.change" ]
28,455
28,456
u247371045
ruby
p00056
primes = Array.new(50000, true) primes[0, 2] = [false, false] 2.upto(50000 - 1){|x| if primes[x] m = 2 while x * m <= 999_999 primes[x * m] = false m += 1 end end } while true n = gets.to_i break if n == 0 sum = 0 3.upto(n/2){|x| sum += 1 if primes[x] && primes[n - x]} puts sum end
primes = Array.new(50000, true) primes[0, 2] = [false, false] 2.upto(50000 - 1){|x| if primes[x] m = 2 while x * m <= 999_999 primes[x * m] = false m += 1 end end } while true n = gets.to_i break if n == 0 sum = 0 2.upto(n/2){|x| sum += 1 if primes[x] && primes[n - x]} puts sum end
[ "literal.number.integer.change" ]
28,457
28,456
u247371045
ruby
p00056
def primes(max) nums = Array.new(max + 1, 1) nums[0] = nums[1] = 0 (2..Math.sqrt(max)).each do |sieve| if nums[sieve] == 1 (2 * sieve).step(max, sieve).each do |num| nums[num] = 0 end end end nums end max = 50 primes = primes(max) nums = (2..max).select { |num| primes[num] == 1 } while line = gets n = line.chomp.to_i break if n == 0 answer = 0 for i in nums j = n - i break if i > j answer += 1 if primes[j] == 1 end puts answer end
def primes(max) nums = Array.new(max + 1, 1) nums[0] = nums[1] = 0 (2..Math.sqrt(max)).each do |sieve| if nums[sieve] == 1 (2 * sieve).step(max, sieve).each do |num| nums[num] = 0 end end end nums end max = 50_000 primes = primes(max) nums = (2..max).select { |num| primes[num] == 1 } while line = gets n = line.chomp.to_i break if n == 0 answer = 0 for i in nums j = n - i break if i > j answer += 1 if primes[j] == 1 end puts answer end
[ "literal.number.integer.change", "assignment.value.change" ]
28,458
28,459
u024281398
ruby
p00056
sn = 50000.0**0.5 + 1 is_prime = [false, false] + [true]*49999 (2..sn).each do |i| next unless is_prime[i] (i*i).step(50000, i).each do |j| is_prime[j] = false end end plist = (2..50000).to_a.select{ |i| is_prime[i] } while gets s = $_.to_i tmp = plist.dup l = tmp.shift h = tmp.pop c = 0 until tmp.empty? if l + h == s c += 1 l = tmp.shift elsif l + h < s l = tmp.shift else h = tmp.pop end end c += 1 if l*2 == s or h*2 == s or l+h == s puts c end
sn = 50000.0**0.5 + 1 is_prime = [false, false] + [true]*49999 (2..sn).each do |i| next unless is_prime[i] (i*i).step(50000, i).each do |j| is_prime[j] = false end end plist = (2..50000).to_a.select{ |i| is_prime[i] } while gets s = $_.to_i break if s == 0 tmp = plist.dup l = tmp.shift h = tmp.pop c = 0 until tmp.empty? if l + h == s c += 1 l = tmp.shift elsif l + h < s l = tmp.shift else h = tmp.pop end end c += 1 if l*2 == s or h*2 == s or l+h == s puts c end
[]
28,466
28,467
u708217907
ruby
p00064
a=[] while gets a<<$_.chomp.split(/[a-z]+/).map(&:to_i) end p a.flatten.inject(:+)
a=[] while gets a<<$_.chomp.split(/[^0-9]+/).map(&:to_i) end p a.flatten.inject(:+)
[ "literal.string.change", "call.arguments.change", "expression.operation.binary.change" ]
28,575
28,576
u461552210
ruby
p00065
a,b=gets(p).split("\n\n"); c=[0]*2000;d=[0]*2000; ans=[]; a.split.map{|s|b=s.to_i;c[b]+=1} b.split.map{|s|b=s.to_i;ans<<b if c[b]>0;d[b]+=1} ans=ans.sort.uniq; ans.map{|a|puts "#{a} #{c[a]+d[a]}"}
a,b=gets(p).split("\n\n"); c=[0]*2000;d=[0]*2000; ans=[]; a.split.map{|s|l=s.to_i;c[l]+=1} b.split.map{|s|b=s.to_i;ans<<b if c[b]>0;d[b]+=1} ans=ans.sort.uniq; ans.map{|a|puts "#{a} #{c[a]+d[a]}"}
[ "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change" ]
28,646
28,647
u868447400
ruby
p00065
pm = {} while (s = gets) != "\n" (n, c) = s.chomp.split(/,/).map(&:to_i) pm[n] = [] if !pm.key?(n) pm[n].push(c) end tm = {} while (s = gets) != "\n" (n, c) = s.chomp.split(/,/).map(&:to_i) tm[n] = [] if !tm.key?(n) tm[n].push(c) end pm.keys.sort.each do |k| if tm.key?(k) puts "#{k} #{pm[k].size + tm[k].size}" end end
pm = {} while (s = gets) != "\n" (n, c) = s.chomp.split(/,/).map(&:to_i) pm[n] = [] if !pm.key?(n) pm[n].push(c) end tm = {} while s = gets (n, c) = s.chomp.split(/,/).map(&:to_i) tm[n] = [] if !tm.key?(n) tm[n].push(c) end pm.keys.sort.each do |k| if tm.key?(k) puts "#{k} #{pm[k].size + tm[k].size}" end end
[ "expression.operation.binary.remove" ]
28,650
28,651
u854447110
ruby
p00071
#!/usr/bin/env ruby def bomb(x, y) return if @field[x][y] != 1 @field[x][y] = 0 -3.upto(3) do |i| next if i.zero? bomb(x + i, y) if (x + i) > 0 && (x + i) < 8 bomb(x, y + i) if (y + i) > 0 && (y + i) < 8 end end n = gets.chomp!.to_i # skip empty line gets n.times do |i| @field = [] 8.times do |r| @field[r] = gets.chomp!.split('').map(&:to_i) end bomb_x = gets.chomp!.to_i bomb_y = gets.chomp!.to_i # simulate bomb bomb(bomb_x - 1, bomb_y - 1) # output result puts "Data #{i + 1}:" 8.times do |r| puts @field[r].join('') end # skip empty-line gets if i + 1 != n end
#!/usr/bin/env ruby def bomb(x, y) return if @field[x][y] != 1 @field[x][y] = 0 -3.upto(3) do |i| next if i.zero? bomb(x + i, y) if (x + i) >= 0 && (x + i) < 8 bomb(x, y + i) if (y + i) >= 0 && (y + i) < 8 end end n = gets.chomp!.to_i # skip empty line gets n.times do |i| @field = [] 8.times do |r| @field[r] = gets.chomp!.split('').map(&:to_i) end bomb_x = gets.chomp!.to_i bomb_y = gets.chomp!.to_i # simulate bomb bomb(bomb_y - 1, bomb_x - 1) # output result puts "Data #{i + 1}:" 8.times do |r| puts @field[r].join('') end # skip empty-line gets if i + 1 != n end
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "identifier.change", "call.arguments.change", "expression.operation.binary.change", "io.output.change" ]
28,818
28,819
u717782380
ruby
p00071
#!/usr/bin/env ruby def bomb(x, y) return if @field[x][y] != 1 @field[x][y] = 0 -3.upto(3) do |i| next if i.zero? bomb(x + i, y) if (x + i) >= 0 && (x + i) < 8 bomb(x, y + i) if (y + i) >= 0 && (y + i) < 8 end end n = gets.chomp!.to_i # skip empty line gets n.times do |i| @field = [] 8.times do |r| @field[r] = gets.chomp!.split('').map(&:to_i) end bomb_x = gets.chomp!.to_i bomb_y = gets.chomp!.to_i # simulate bomb bomb(bomb_x - 1, bomb_y - 1) # output result puts "Data #{i + 1}:" 8.times do |r| puts @field[r].join('') end # skip empty-line gets if i + 1 != n end
#!/usr/bin/env ruby def bomb(x, y) return if @field[x][y] != 1 @field[x][y] = 0 -3.upto(3) do |i| next if i.zero? bomb(x + i, y) if (x + i) >= 0 && (x + i) < 8 bomb(x, y + i) if (y + i) >= 0 && (y + i) < 8 end end n = gets.chomp!.to_i # skip empty line gets n.times do |i| @field = [] 8.times do |r| @field[r] = gets.chomp!.split('').map(&:to_i) end bomb_x = gets.chomp!.to_i bomb_y = gets.chomp!.to_i # simulate bomb bomb(bomb_y - 1, bomb_x - 1) # output result puts "Data #{i + 1}:" 8.times do |r| puts @field[r].join('') end # skip empty-line gets if i + 1 != n end
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change", "io.output.change" ]
28,820
28,819
u717782380
ruby
p00074
loop do record_time=2*3600#????????§???????§???° time=gets.chomp.split(nil).map(&:to_i) break if time.all?{|x|x==-1} t=time[2] t+=time[1]*60 t+=time[0]*3600 #?¨?????????? rest_of_time=record_time-t h=rest_of_time/3600#hour m=(rest_of_time%3600)/60#minute s=rest_of_time%60#second printf("%02d:%02d:%02d \n",h,m,s) #3???????????¢?????? rest_of_time=record_time-t/3 h=rest_of_time/3600#hour m=(rest_of_time%3600)/60#minute s=rest_of_time%60#second printf("%02d:%02d:%02d \n",h,m,s) end
loop do record_time=2*3600#????????§???????§???° time=gets.chomp.split(nil).map(&:to_i) break if time.all?{|x|x==-1} t=time[2] t+=time[1]*60 t+=time[0]*3600 #?¨?????????? rest_of_time=record_time-t h=rest_of_time/3600#hour m=(rest_of_time%3600)/60#minute s=rest_of_time%60#second printf("%02d:%02d:%02d\n",h,m,s) #3???????????¢?????? rest_of_time=(record_time-t)*3 h=rest_of_time/3600#hour m=(rest_of_time%3600)/60#minute s=rest_of_time%60#second printf("%02d:%02d:%02d\n",h,m,s) end
[ "literal.string.change", "call.arguments.change", "io.output.change", "assignment.value.change", "expression.operation.binary.change" ]
29,267
29,268
u287407095
ruby
p00077
puts gets.chomp.gsub(/@(\d)(.)/) {|m| m[2] * m[1].to_i}
while line = gets puts line.chomp.gsub(/@(\d)(.)/) {|m| m[2] * m[1].to_i} end
[ "call.add" ]
29,618
29,619
u670581076
ruby
p00079
def aop() i = 0 b = [] a =[] c = [] while c = gets b = c.split(',').map(&:to_f) puts b a[i] = b i += 1 end t = 0 for i in 1..a.length-2 x = ((a[0][0]-a[i][0])**2 + (a[0][1]-a[i][1])**2)**(1/2.0) y = ((a[0][0]-a[i+1][0])**2 + (a[0][1]-a[i+1][1])**2)**(1/2.0) z = ((a[i+1][0]-a[i][0])**2 + (a[i+1][1]-a[i][1])**2)**(1/2.0) w = (x + y + z)/2.0 s = (w*(w-x)*(w-y)*(w-z))**(1/2.0) t += s end puts t end aop()
def aop() i = 0 b = [] a =[] c = [] while c = gets b = c.split(',').map(&:to_f) a[i] = b i += 1 end t = 0 for i in 1..a.length-2 x = ((a[0][0]-a[i][0])**2 + (a[0][1]-a[i][1])**2)**(1/2.0) y = ((a[0][0]-a[i+1][0])**2 + (a[0][1]-a[i+1][1])**2)**(1/2.0) z = ((a[i+1][0]-a[i][0])**2 + (a[i+1][1]-a[i][1])**2)**(1/2.0) w = (x + y + z)/2.0 s = (w*(w-x)*(w-y)*(w-z))**(1/2.0) t += s end puts t end aop()
[ "call.remove" ]
30,030
30,031
u670287874
ruby
p00079
point = Array.new def solve(point) source = point[0] point.delete_at(0) # point.sort{|p1,p2| p1[1] <=> p2[1]} sum = 0 while point.size > 1 do p1 = point[0] p2 = point[1] a = getDistance(source, p1) b = getDistance(source,p2) c = getDistance(p1, p2) z = (a + b + c) / 2 sum += getArea(a, b, c, z) #不要になった座標は削除する point.delete_at(0) end sum end def getDistance(p1, p2) Math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) end def getArea(l1, l2, l3, z) Math.sqrt(z * (z - l1) * (z - l2) * (z - l3)) end while input = $stdin.gets do point << input.chomp.split(",").map(&:to_i) end printf "%.6f\n", solve(point)
point = Array.new def solve(point) source = point[0] point.delete_at(0) # point.sort{|p1,p2| p1[1] <=> p2[1]} sum = 0 while point.size > 1 do p1 = point[0] p2 = point[1] a = getDistance(source, p1) b = getDistance(source,p2) c = getDistance(p1, p2) z = (a + b + c) / 2 sum += getArea(a, b, c, z) #不要になった座標は削除する point.delete_at(0) end sum end def getDistance(p1, p2) Math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) end def getArea(l1, l2, l3, z) Math.sqrt(z * (z - l1) * (z - l2) * (z - l3)) end while input = $stdin.gets do point << input.chomp.split(",").map(&:to_f) end printf "%.6f\n", solve(point)
[ "call.arguments.change", "expression.operation.binary.change" ]
30,032
30,033
u985809245
ruby
p00069
def amida(n,m,s,l) a=Array.new(n) {|i| i+1} l.each do |i| i.each_with_index do |j,id| a[id],a[id+1]=a[id+1],a[id] if j==1 end end return a[s-1]==m ? true : false end loop do break if gets.chomp=="0" n,m,s,d,l=$_.to_i,gets.to_i,gets.to_i,gets.to_i,[] d.times do l<<gets.chomp.split("").map(&:to_i) end if amida(n,m,s,l) then puts 0 else bf=false ll= Marshal.load(Marshal.dump(l)) l.each_with_index do |i, idi| i.each_with_index do |j, idj| if j==1 then ll[idi][[0,idj-1].max]=1 ll[idi][idj]=1 ll[idi][[n-2,idj+1].min]=1 end end end ll.each_with_index do |i, idi| i.each_with_index do |j, idj| if j==0 then l3= Marshal.load(Marshal.dump(l)) l3[idi][idj]=1 puts "#{idi+1} #{idj+1}" if bf=amida(n,m,s,l3) end end break if bf end puts 1 unless bf end end
def amida(n,m,s,l) a=Array.new(n) {|i| i+1} l.each do |i| i.each_with_index do |j,id| a[id],a[id+1]=a[id+1],a[id] if j==1 end end return a[s-1]==m ? true : false end loop do break if gets.chomp=="0" n,m,s,d,l=$_.to_i,gets.to_i,gets.to_i,gets.to_i,[] d.times do l<<gets.chomp.split("").map(&:to_i) end if amida(n,m,s,l) then puts 0 else bf=false ll= Marshal.load(Marshal.dump(l)) l.each_with_index do |i, idi| i.each_with_index do |j, idj| if j==1 then ll[idi][[0,idj-1].max]=1 ll[idi][idj]=1 ll[idi][[n-2,idj+1].min]=1 end end end ll.each_with_index do |i, idi| i.each_with_index do |j, idj| if j==0 then l3= Marshal.load(Marshal.dump(l)) l3[idi][idj]=1 puts "#{idi+1} #{idj+1}" if bf=amida(n,m,s,l3) end break if bf end break if bf end puts 1 unless bf end end
[]
30,146
30,147
u461552210
ruby
p00069
def amida(n,m,s,l) a=Array.new(n) {|i| i+1} l.each do |i| # puts "#{i.join}" i.each_with_index do |j,id| a[id],a[id+1]=a[id+1],a[id] if j==1 end end # p a # puts "m:#{m}, s:#{s}" return a[s-1]==m ? true : false end loop do break if gets.chomp=="0" n,m,s,d,l=$_.to_i,gets.to_i,gets.to_i,gets.to_i,[] # puts "#{n},#{m},#{s},#{d}" d.times do l<<gets.chomp.split("").map(&:to_i) end # puts "m:#{m}, s:#{s}" if amida(n,m,s,l) then puts 0 else bf=false ll= Marshal.load(Marshal.dump(l)) l.each_with_index do |i, idi| #0010???0111??¨???????????????1?????£???0???1??¨??´??°??????0111?????????each??§0?????´???1?????????(0010???1010)?????????????????????????????? i.each_with_index do |j, idj| if j==1 then ll[idi][[0,idj-1].max]=1 ll[idi][idj]=1 ll[idi][[n-2,idj+1].min]=1 end end end # p ll ll.each_with_index do |i, idi| i.each_with_index do |j, idj| # puts "i:#{idi},j:#{idj}" if j==0 if j==0 then l3= Marshal.load(Marshal.dump(l)) l3[idi][idj]=1 puts "#{idi+1} #{idj+1}" if bf=amida(n,m,s,l3) end end break if bf end puts 1 unless bf end end
def amida(n,m,s,l) a=Array.new(n) {|i| i+1} l.each do |i| i.each_with_index do |j,id| a[id],a[id+1]=a[id+1],a[id] if j==1 end end return a[s-1]==m ? true : false end loop do break if gets.chomp=="0" n,m,s,d,l=$_.to_i,gets.to_i,gets.to_i,gets.to_i,[] d.times do l<<gets.chomp.split("").map(&:to_i) end if amida(n,m,s,l) then puts 0 else bf=false ll= Marshal.load(Marshal.dump(l)) l.each_with_index do |i, idi| i.each_with_index do |j, idj| if j==1 then ll[idi][[0,idj-1].max]=1 ll[idi][idj]=1 ll[idi][[n-2,idj+1].min]=1 end end end ll.each_with_index do |i, idi| i.each_with_index do |j, idj| if j==0 then l3= Marshal.load(Marshal.dump(l)) l3[idi][idj]=1 puts "#{idi+1} #{idj+1}" if bf=amida(n,m,s,l3) end break if bf end break if bf end puts 1 unless bf end end
[]
30,148
30,147
u461552210
ruby
p00069
def goal?(amida,m,s) s == 1 + (amida.inject(m-1) do |s,i| if s>1 && i[s-1]=="1" s-1 elsif i[s]=="1" s+1 else s end end) end loop do n = gets.to_i break if n==0 m,s,d = 3.times.map{ gets.to_i } amida = d.times.map{ gets.chomp } if goal?(amida,m,s) puts 0 next end catch :find do amida.each_with_index do |a,i| n.times do |j| if "0#{a}0"[j,3]=="000" added = amida.dup b = a.dup b[j] = "1" added[i] = b if goal?(added,m,s) puts "#{i+1} #{j+1}" throw :find end end end end puts 1 end end
def goal?(amida,m,s) s == 1 + (amida.inject(m-1) do |s,i| if s>=1 && i[s-1]=="1" s-1 elsif i[s]=="1" s+1 else s end end) end loop do n = gets.to_i break if n==0 m,s,d = 3.times.map{ gets.to_i } amida = d.times.map{ gets.chomp } if goal?(amida,m,s) puts 0 next end catch :find do amida.each_with_index do |a,i| n.times do |j| if "0#{a}0"[j,3]=="000" added = amida.dup b = a.dup b[j] = "1" added[i] = b if goal?(added,m,s) puts "#{i+1} #{j+1}" throw :find end end end end puts 1 end end
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
30,152
30,153
u662700808
ruby
p00084
arr, ans = gets.split.map{ |i| i.delete(",.") }, [] arr.each do |str| p str.length ans << str if (3..6).include?(str.length) end puts ans.join(" ")
arr, ans = gets.split.map{ |i| i.delete(",.") }, [] arr.each do |str| ans << str if (3..6).include?(str.length) end puts ans.join(" ")
[ "call.remove" ]
30,382
30,383
u814658648
ruby
p00080
while true q=gets.to_f break if(q==-1) x=q/2 p x while (x**3-q).abs>=0.00001 x=x-((x**3-q)/(3*x*x)) end printf("%.6f\n", x) end
while true q=gets.to_f break if(q==-1) x=q/2 while (x**3-q).abs>0.00001*q x=x-((x**3-q)/(3*x*x)) end printf("%.6f\n", x) end
[ "call.remove", "expression.operator.compare.change", "expression.operation.binary.change" ]
30,786
30,784
u287407095
ruby
p00080
readlines.map(&:to_f).each{|q| break if q == -1 x = q / 2.0 loop do break if (x * x * x - q).abs < 0.0001 * q x -= (x * x * x - q)/(3.0*x * x) end puts "%.6f" % x }
readlines.map(&:to_f).each{|q| break if q == -1 x = q / 2.0 loop do break if (x * x * x - q).abs < 0.00001 * q x -= (x * x * x - q)/(3.0*x * x) end puts "%.8f" % x }
[ "literal.number.float.change", "control_flow.branch.if.condition.change", "literal.string.change", "call.arguments.change", "expression.operation.binary.change", "io.output.change" ]
30,789
30,790
u960312159
ruby
p00080
readlines.map(&:to_f).each{|q| break if q == -1 x = q / 2.0 loop do break if (x * x * x - q).abs < 0.0001 * q x -= (x * x * x - q)/(3.0*x * x) end puts "%.8f" % x }
readlines.map(&:to_f).each{|q| break if q == -1 x = q / 2.0 loop do break if (x * x * x - q).abs < 0.00001 * q x -= (x * x * x - q)/(3.0*x * x) end puts "%.8f" % x }
[ "literal.number.float.change", "control_flow.branch.if.condition.change" ]
30,791
30,790
u960312159
ruby
p00082
c = [4,1,4,1,2,1,2,1] readlines.each do |l| p = l.split.map(&:to_i) ans = 7.times.map{ c=c.rotate }.sort do |a,b| t = (a.zip(p).map{|i,j| [i-j,0].max}.inject(:+) <=> b.zip(p).map{|i,j| [i-j,0].max}.inject(:+)) t==0 ? a.join.to_i <=> b.join.to_i : t end.first puts ans.join(" ") end
c = [4,1,4,1,2,1,2,1] readlines.each do |l| p = l.split.map(&:to_i) ans = 8.times.map{ c=c.rotate }.sort do |a,b| t = (a.zip(p).map{|i,j| [i-j,0].max}.inject(:+) <=> b.zip(p).map{|i,j| [i-j,0].max}.inject(:+)) t==0 ? a.join.to_i <=> b.join.to_i : t end.first puts ans.join(" ") end
[ "literal.number.integer.change", "assignment.value.change" ]
30,879
30,880
u662700808
ruby
p00085
readlines.each do |l| n,m = l.split.map(&:to_i) break if n==0 && m==0 i = n p = (0..(n-1)).to_a while p.size>1 p.delete_at(i=((i+m) % p.size)) i = (i-1) % p.size end puts p.first end
readlines.each do |l| n,m = l.split.map(&:to_i) break if n==0 && m==0 i = -1 p = (0..(n-1)).to_a while p.size>1 p.delete_at(i=((i+m) % p.size)) i = (i-1) % p.size end puts p.first+1 end
[ "assignment.value.change", "expression.operation.unary.add" ]
31,089
31,090
u662700808
ruby
p00088
def main(input = STDIN) plane = {" " => "101", "'" => "000000", "," => "000011", "-" => "10010001", "." => "010001", "?" => "000001", "A" => "100101", "B" => "10011010", "C" => "0101", "D" => "0001", "E" => "110", "F" => "01001", "G" => "10011011", "H" => "010000", "I" => "0111", "J" => "10011000", "K" => "0110", "L" => "00100", "M" => "10011001", "N" => "10011110", "O" => "00101", "P" => "111", "Q" => "10011111", "R" => "1000", "S" => "00110", "T" => "00111", "U" => "10011100", "V" => "10011101", "W" => "000010", "X" => "10010010", "Y" => "10010011", "Z" => "10010000"} code = ["A"] for i in 1..25 code[i] = code[i - 1].next end code.push " ", ".", ",", "-", "'", "?" while text = input.gets output = [] coded = text.chomp.split(//).map{|char|plane[char]}.join coded << "0" * (-(coded.size + 1) % 5) for i in 0..coded.size / 5 output << code[coded.slice(i * 5, 5).to_i(2)] end puts output.join end end main
def main(input = STDIN) plane = {" " => "101", "'" => "000000", "," => "000011", "-" => "10010001", "." => "010001", "?" => "000001", "A" => "100101", "B" => "10011010", "C" => "0101", "D" => "0001", "E" => "110", "F" => "01001", "G" => "10011011", "H" => "010000", "I" => "0111", "J" => "10011000", "K" => "0110", "L" => "00100", "M" => "10011001", "N" => "10011110", "O" => "00101", "P" => "111", "Q" => "10011111", "R" => "1000", "S" => "00110", "T" => "00111", "U" => "10011100", "V" => "10011101", "W" => "000010", "X" => "10010010", "Y" => "10010011", "Z" => "10010000"} code = ["A"] for i in 1..25 code[i] = code[i - 1].next end code.push " ", ".", ",", "-", "'", "?" while text = input.gets output = [] coded = text.chomp.split(//).map{|char|plane[char]}.join coded << "0" * (-coded.size % 5) for i in 0...coded.size / 5 output << code[coded.slice(i * 5, 5).to_i(2)] end puts output.join end end main
[]
31,353
31,354
u514597327
ruby
p00088
code_a = Hash[ *%w( ' 000000 , 000011 - 10010001 . 010001 ? 000001 A 100101 B 10011010 C 0101 D 0001 E 110 F 01001 G 10011011 H 010000 I 0111 J 10011000 K 0110 L 00100 M 10011001 N 10011110 O 00101 P 111 Q 10011111 R 1000 S 00110 T 00111 U 10011100 V 10011101 W 000010 X 10010010 Y 10010011 Z 10010000 )] code_a[' '] = '101' code_b = Hash[*%w( 11011 . 11100 , 11101 - 11110 ' 11111 ? )] (?A..?Z).each{|c| code_b["%05b" % (c.ord - ?A.ord)] = c } code_b['11010'] = " " while gets puts $_ .chomp .each_char .map{|c| code_a[c]} .join .scan(/.{1,5}/) .map{|s| code_b[?0 * (5-s.size) + s]} .join end
code_a = Hash[ *%w( ' 000000 , 000011 - 10010001 . 010001 ? 000001 A 100101 B 10011010 C 0101 D 0001 E 110 F 01001 G 10011011 H 010000 I 0111 J 10011000 K 0110 L 00100 M 10011001 N 10011110 O 00101 P 111 Q 10011111 R 1000 S 00110 T 00111 U 10011100 V 10011101 W 000010 X 10010010 Y 10010011 Z 10010000 )] code_a[' '] = '101' code_b = Hash[*%w( 11011 . 11100 , 11101 - 11110 ' 11111 ? )] (?A..?Z).each{|c| code_b["%05b" % (c.ord - ?A.ord)] = c } code_b['11010'] = " " while gets puts $_ .chomp .each_char .map{|c| code_a[c]} .join .scan(/.{1,5}/) .map{|s| code_b[s + ?0 * (5 - s.size)]} .join end
[ "expression.operation.binary.remove" ]
31,355
31,356
u797180951
ruby
p00088
words = [" ", "\'", ",", "-", ".", "?"] words += %{ABCDEFGHIJKLMNOPQRSTUVWXYZ}.split("") code = %w{101 000000 000011 10010001 010001 000001 100101 10011010 0101 0001 110 01001 10011011 010000 0111 10011000 0110 00100 10011001 10011110 00101 111 10011111 1000 00110 00111 10011100 10011101 000010 10010010 10010011 10010000} n_code = %w{11010 11110 11100 11101 11011 11111 00000 00001 00010 00011 00100 00101 00110 00111 01000 01001 01010 01011 01100 01101 01110 01111 10000 10001 10010 10011 10100 10101 10110 10111 11000 11001} while gets s = "" $_.split("").each do |w| s += code[words.find_index(w)] end sz = s.size%5 s += "0"*((5-sz)%5) ret = "" (s.size/5).times do |i| ret += words[n_code.find_index(s[i*5,5])] end puts ret end
words = [" ", "\'", ",", "-", ".", "?"] words += %{ABCDEFGHIJKLMNOPQRSTUVWXYZ}.split("") code = %w{101 000000 000011 10010001 010001 000001 100101 10011010 0101 0001 110 01001 10011011 010000 0111 10011000 0110 00100 10011001 10011110 00101 111 10011111 1000 00110 00111 10011100 10011101 000010 10010010 10010011 10010000} n_code = %w{11010 11110 11100 11101 11011 11111 00000 00001 00010 00011 00100 00101 00110 00111 01000 01001 01010 01011 01100 01101 01110 01111 10000 10001 10010 10011 10100 10101 10110 10111 11000 11001} while gets s = "" $_.chomp.split("").each do |w| s += code[words.find_index(w)] end sz = s.size%5 s += "0"*((5-sz)%5) ret = "" (s.size/5).times do |i| ret += words[n_code.find_index(s[i*5,5])] end puts ret end
[ "call.add" ]
31,357
31,358
u811434779
ruby
p00088
mp = {} mp[" "] = "101" mp["'"] = "000000" mp[","] = "000011" mp["-"] = "10010001" mp["."] = "010001" mp["?"] = "000001" mp["A"] = "100101" mp["B"] = "10011010" mp["C"] = "0101" mp["D"] = "0001" mp["E"]="110" mp["F"]="01001" mp["G"]="10011011" mp["H"]="010000" mp["I"]="0111" mp["J"]="10011000" mp["K"]="0110" mp["L"]="00100" mp["N"]="10011001" mp["M"]="10011110" mp["O"]="00101" mp["P"]="111" mp["Q"]="10011111" mp["R"]="1000" mp["S"]="00110" mp["T"]="00111" mp["U"]="10011100" mp["V"]="10011101" mp["W"]="000010" mp["X"]="10010010" mp["Y"]="10010011" mp["Z"]="10010000" gyaku = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?" while s=gets s=s.chomp t="" for i in 0...s.length t+=mp[s[i]] end n = t.length t += "0"*((5-n%5)%5) n = t.length res = "" for i in 0...(n/5) beg = i*5 id = 0 for j in 0...5 id*=2 id+=(t[beg+j]=="0" ? 0 : 1) end res += gyaku[id] end puts res end
mp = {} mp[" "] = "101" mp["'"] = "000000" mp[","] = "000011" mp["-"] = "10010001" mp["."] = "010001" mp["?"] = "000001" mp["A"] = "100101" mp["B"] = "10011010" mp["C"] = "0101" mp["D"] = "0001" mp["E"]="110" mp["F"]="01001" mp["G"]="10011011" mp["H"]="010000" mp["I"]="0111" mp["J"]="10011000" mp["K"]="0110" mp["L"]="00100" mp["M"]="10011001" mp["N"]="10011110" mp["O"]="00101" mp["P"]="111" mp["Q"]="10011111" mp["R"]="1000" mp["S"]="00110" mp["T"]="00111" mp["U"]="10011100" mp["V"]="10011101" mp["W"]="000010" mp["X"]="10010010" mp["Y"]="10010011" mp["Z"]="10010000" gyaku = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?" while s=gets s=s.chomp t="" for i in 0...s.length t+=mp[s[i]] end n = t.length t += "0"*((5-n%5)%5) n = t.length res = "" for i in 0...(n/5) beg = i*5 id = 0 for j in 0...5 id*=2 id+=(t[beg+j]=="0" ? 0 : 1) end res += gyaku[id] end puts res end
[ "literal.string.change", "assignment.variable.change", "variable_access.subscript.index.change" ]
31,359
31,360
u289594538
ruby
p00088
class String @@encode = {} @@decode = {} def encode res = split('').map{ |c| @@encode[c] }.join res + '0' * (5 - res.size % 5) end def decode scan(/.{5}/).map{ |s| @@decode[s] }.join end @@encode[" "] = "101" @@encode["'"] = "000000" @@encode[","] = "000011" @@encode["-"] = "10010001" @@encode["."] = "010001" @@encode["?"] = "000001" @@encode["A"] = "100101" @@encode["B"] = "10011010" @@encode["C"] = "0101" @@encode["D"] = "0001" @@encode["E"] = "110" @@encode["F"] = "01001" @@encode["G"] = "10011011" @@encode["H"] = "010000" @@encode["I"] = "0111" @@encode["J"] = "10011000" @@encode["K"] = "0110" @@encode["L"] = "00100" @@encode["M"] = "10011001" @@encode["N"] = "10011110" @@encode["O"] = "00101" @@encode["P"] = "111" @@encode["Q"] = "10011111" @@encode["R"] = "1000" @@encode["S"] = "00110" @@encode["T"] = "00111" @@encode["U"] = "10011100" @@encode["V"] = "10011101" @@encode["W"] = "000010" @@encode["X"] = "10010010" @@encode["Y"] = "10010011" @@encode["Z"] = "10010000" @@decode["00000"] = "A" @@decode["00001"] = "B" @@decode["00010"] = "C" @@decode["00011"] = "D" @@decode["00100"] = "E" @@decode["00101"] = "F" @@decode["00110"] = "G" @@decode["00111"] = "H" @@decode["01000"] = "I" @@decode["01001"] = "J" @@decode["01010"] = "K" @@decode["01011"] = "L" @@decode["01100"] = "M" @@decode["01101"] = "N" @@decode["01110"] = "O" @@decode["01111"] = "P" @@decode["10000"] = "Q" @@decode["10001"] = "R" @@decode["10010"] = "S" @@decode["10011"] = "T" @@decode["10100"] = "U" @@decode["10101"] = "V" @@decode["10110"] = "W" @@decode["10111"] = "X" @@decode["11000"] = "Y" @@decode["11001"] = "Z" @@decode["11010"] = " " @@decode["11011"] = "." @@decode["11100"] = "," @@decode["11101"] = "-" @@decode["11110"] = "'" @@decode["11111"] = "?" end while line = gets puts line.encode.decode end
class String @@encode = {} @@decode = {} def encode res = split('').map{ |c| @@encode[c] }.join res + '0' * ((5 - res.size % 5) % 5) end def decode scan(/.{5}/).map{ |s| @@decode[s] }.join end @@encode[" "] = "101" @@encode["'"] = "000000" @@encode[","] = "000011" @@encode["-"] = "10010001" @@encode["."] = "010001" @@encode["?"] = "000001" @@encode["A"] = "100101" @@encode["B"] = "10011010" @@encode["C"] = "0101" @@encode["D"] = "0001" @@encode["E"] = "110" @@encode["F"] = "01001" @@encode["G"] = "10011011" @@encode["H"] = "010000" @@encode["I"] = "0111" @@encode["J"] = "10011000" @@encode["K"] = "0110" @@encode["L"] = "00100" @@encode["M"] = "10011001" @@encode["N"] = "10011110" @@encode["O"] = "00101" @@encode["P"] = "111" @@encode["Q"] = "10011111" @@encode["R"] = "1000" @@encode["S"] = "00110" @@encode["T"] = "00111" @@encode["U"] = "10011100" @@encode["V"] = "10011101" @@encode["W"] = "000010" @@encode["X"] = "10010010" @@encode["Y"] = "10010011" @@encode["Z"] = "10010000" @@decode["00000"] = "A" @@decode["00001"] = "B" @@decode["00010"] = "C" @@decode["00011"] = "D" @@decode["00100"] = "E" @@decode["00101"] = "F" @@decode["00110"] = "G" @@decode["00111"] = "H" @@decode["01000"] = "I" @@decode["01001"] = "J" @@decode["01010"] = "K" @@decode["01011"] = "L" @@decode["01100"] = "M" @@decode["01101"] = "N" @@decode["01110"] = "O" @@decode["01111"] = "P" @@decode["10000"] = "Q" @@decode["10001"] = "R" @@decode["10010"] = "S" @@decode["10011"] = "T" @@decode["10100"] = "U" @@decode["10101"] = "V" @@decode["10110"] = "W" @@decode["10111"] = "X" @@decode["11000"] = "Y" @@decode["11001"] = "Z" @@decode["11010"] = " " @@decode["11011"] = "." @@decode["11100"] = "," @@decode["11101"] = "-" @@decode["11110"] = "'" @@decode["11111"] = "?" end while line = gets puts line.encode.decode end
[]
31,363
31,364
u439230786
ruby
p00088
class String @@encode = {} @@decode = {} def encode res = split('').map{ |c| @@encode[c] }.join res + '0' * (5 - res.size % 5) % 5 end def decode scan(/.{5}/).map{ |s| @@decode[s] }.join end @@encode[" "] = "101" @@encode["'"] = "000000" @@encode[","] = "000011" @@encode["-"] = "10010001" @@encode["."] = "010001" @@encode["?"] = "000001" @@encode["A"] = "100101" @@encode["B"] = "10011010" @@encode["C"] = "0101" @@encode["D"] = "0001" @@encode["E"] = "110" @@encode["F"] = "01001" @@encode["G"] = "10011011" @@encode["H"] = "010000" @@encode["I"] = "0111" @@encode["J"] = "10011000" @@encode["K"] = "0110" @@encode["L"] = "00100" @@encode["M"] = "10011001" @@encode["N"] = "10011110" @@encode["O"] = "00101" @@encode["P"] = "111" @@encode["Q"] = "10011111" @@encode["R"] = "1000" @@encode["S"] = "00110" @@encode["T"] = "00111" @@encode["U"] = "10011100" @@encode["V"] = "10011101" @@encode["W"] = "000010" @@encode["X"] = "10010010" @@encode["Y"] = "10010011" @@encode["Z"] = "10010000" @@decode["00000"] = "A" @@decode["00001"] = "B" @@decode["00010"] = "C" @@decode["00011"] = "D" @@decode["00100"] = "E" @@decode["00101"] = "F" @@decode["00110"] = "G" @@decode["00111"] = "H" @@decode["01000"] = "I" @@decode["01001"] = "J" @@decode["01010"] = "K" @@decode["01011"] = "L" @@decode["01100"] = "M" @@decode["01101"] = "N" @@decode["01110"] = "O" @@decode["01111"] = "P" @@decode["10000"] = "Q" @@decode["10001"] = "R" @@decode["10010"] = "S" @@decode["10011"] = "T" @@decode["10100"] = "U" @@decode["10101"] = "V" @@decode["10110"] = "W" @@decode["10111"] = "X" @@decode["11000"] = "Y" @@decode["11001"] = "Z" @@decode["11010"] = " " @@decode["11011"] = "." @@decode["11100"] = "," @@decode["11101"] = "-" @@decode["11110"] = "'" @@decode["11111"] = "?" end while line = gets puts line.encode.decode end
class String @@encode = {} @@decode = {} def encode res = split('').map{ |c| @@encode[c] }.join res + '0' * ((5 - res.size % 5) % 5) end def decode scan(/.{5}/).map{ |s| @@decode[s] }.join end @@encode[" "] = "101" @@encode["'"] = "000000" @@encode[","] = "000011" @@encode["-"] = "10010001" @@encode["."] = "010001" @@encode["?"] = "000001" @@encode["A"] = "100101" @@encode["B"] = "10011010" @@encode["C"] = "0101" @@encode["D"] = "0001" @@encode["E"] = "110" @@encode["F"] = "01001" @@encode["G"] = "10011011" @@encode["H"] = "010000" @@encode["I"] = "0111" @@encode["J"] = "10011000" @@encode["K"] = "0110" @@encode["L"] = "00100" @@encode["M"] = "10011001" @@encode["N"] = "10011110" @@encode["O"] = "00101" @@encode["P"] = "111" @@encode["Q"] = "10011111" @@encode["R"] = "1000" @@encode["S"] = "00110" @@encode["T"] = "00111" @@encode["U"] = "10011100" @@encode["V"] = "10011101" @@encode["W"] = "000010" @@encode["X"] = "10010010" @@encode["Y"] = "10010011" @@encode["Z"] = "10010000" @@decode["00000"] = "A" @@decode["00001"] = "B" @@decode["00010"] = "C" @@decode["00011"] = "D" @@decode["00100"] = "E" @@decode["00101"] = "F" @@decode["00110"] = "G" @@decode["00111"] = "H" @@decode["01000"] = "I" @@decode["01001"] = "J" @@decode["01010"] = "K" @@decode["01011"] = "L" @@decode["01100"] = "M" @@decode["01101"] = "N" @@decode["01110"] = "O" @@decode["01111"] = "P" @@decode["10000"] = "Q" @@decode["10001"] = "R" @@decode["10010"] = "S" @@decode["10011"] = "T" @@decode["10100"] = "U" @@decode["10101"] = "V" @@decode["10110"] = "W" @@decode["10111"] = "X" @@decode["11000"] = "Y" @@decode["11001"] = "Z" @@decode["11010"] = " " @@decode["11011"] = "." @@decode["11100"] = "," @@decode["11101"] = "-" @@decode["11110"] = "'" @@decode["11111"] = "?" end while line = gets puts line.encode.decode end
[]
31,365
31,364
u439230786
ruby
p00087
while _ = $stdin.gets stack = [] terms = _.chomp.split(/ /) terms.each do |t| case t when /^\A\d+\z/ stack << t.to_i when '+' stack << stack.pop(2).inject(:+) when '-' stack << stack.pop(2).inject(:-) when '/' stack << stack.pop(2).inject(:/) when '*' stack << stack.pop(2).inject(:*) end end puts('%.6f' % stack[0]) end
while _ = $stdin.gets stack = [] terms = _.chomp.split(/ /) terms.each do |t| case t when /^\A-?\d+\z/ stack << t.to_f when '+' stack << stack.pop(2).inject(:+) when '-' stack << stack.pop(2).inject(:-) when '/' stack << stack.pop(2).inject(:/) when '*' stack << stack.pop(2).inject(:*) end end puts('%.6f' % stack[0]) end
[ "call.function.change", "type_conversion.to_float.change", "type_conversion.to_number.change" ]
31,696
31,697
u810567623
ruby
p00087
while _ = $stdin.gets stack = [] terms = _.chomp.split(/ /) terms.each do |t| case t when /^\A\d+\z/ stack << t.to_f when '+' stack << stack.pop(2).inject(:+) when '-' stack << stack.pop(2).inject(:-) when '/' stack << stack.pop(2).inject(:/) when '*' stack << stack.pop(2).inject(:*) end end puts('%.6f' % stack[0]) end
while _ = $stdin.gets stack = [] terms = _.chomp.split(/ /) terms.each do |t| case t when /^\A-?\d+\z/ stack << t.to_f when '+' stack << stack.pop(2).inject(:+) when '-' stack << stack.pop(2).inject(:-) when '/' stack << stack.pop(2).inject(:/) when '*' stack << stack.pop(2).inject(:*) end end puts('%.6f' % stack[0]) end
[]
31,698
31,697
u810567623
ruby
p00087
while _ = $stdin.gets stack = [] terms = _.chomp.split(/ /) terms.each do |t| case t when /^\A\d+\z/ stack << t.to_f when '+' stack << stack.pop(2).inject(:+) when '-' stack << stack.pop(2).inject(:-) when '/' stack << stack.pop(2).inject(:/) when '*' stack << stack.pop(2).inject(:*) end end puts('%.6f' % (stack[0] || 0)) end
while _ = $stdin.gets stack = [] terms = _.chomp.split(/ /) terms.each do |t| case t when /^\A-?\d+\z/ stack << t.to_f when '+' stack << stack.pop(2).inject(:+) when '-' stack << stack.pop(2).inject(:-) when '/' stack << stack.pop(2).inject(:/) when '*' stack << stack.pop(2).inject(:*) end end puts('%.6f' % stack[0]) end
[ "call.arguments.change" ]
31,699
31,697
u810567623
ruby
p00087
while _ = $stdin.gets stack = [] terms = _.chomp.split(/ /) terms.each do |t| case t when /^\A\d+\z/ stack << t.to_f when '+' stack << stack.pop(2).inject(:+) when '-' stack << stack.pop(2).inject(:-) when '/' stack << stack.pop(2).inject(:/) when '*' stack << stack.pop(2).inject(:*) else raise _ end end puts('%.6f' % stack[0]) end
while _ = $stdin.gets stack = [] terms = _.chomp.split(/ /) terms.each do |t| case t when /^\A-?\d+\z/ stack << t.to_f when '+' stack << stack.pop(2).inject(:+) when '-' stack << stack.pop(2).inject(:-) when '/' stack << stack.pop(2).inject(:/) when '*' stack << stack.pop(2).inject(:*) end end puts('%.6f' % stack[0]) end
[ "call.remove" ]
31,700
31,697
u810567623
ruby
p00087
$<.each do |line| stack = line.chomp.split #逆ポーランド記法 n = stack.inject([]) do |s, x| x =~ /[0-9]/ ? s << x : s << eval(s.pop(2).join(x)) end puts sprintf("%.6f", n.first + 0) end
$<.each do |line| stack = line.chomp.split #逆ポーランド記法 n = stack.inject([]) do |s, x| x =~ /[0-9]/ ? s << x.to_f : s << eval(s.pop(2).join(x)) end puts sprintf("%.6f", n.first + 0) end
[ "call.add" ]
31,701
31,702
u858664023
ruby
p00093
require 'date' f=nil;while(a,b=gets.split.map(&:to_i))!=[0,0]do if f then puts end;f=1 z=a.step(b).select{|i|Date.new(i).leap?} if z.size==0 then puts'NA'else z.each{|e|p e}end end
require 'date' f=nil;while(a,b=gets.split.map(&:to_i))!=[0,0]do if f then puts end;f=1 z=a.step(b).select{|i|Date.leap?(i)} if z.size==0 then puts'NA'else z.each{|e|p e}end end
[ "assignment.value.change", "identifier.change", "call.remove" ]
31,810
31,811
u300645821
ruby
p00093
f=nil;while(a,b=gets.split.map(&:to_i))!=[0,0]do if f then puts end;f=1 z=a.step(b).select{|i|Date.leap?(i)} if z.size==0 then puts'NA'else z.each{|e|p e}end end
require 'date' f=nil;while(a,b=gets.split.map(&:to_i))!=[0,0]do if f then puts end;f=1 z=a.step(b).select{|i|Date.leap?(i)} if z.size==0 then puts'NA'else z.each{|e|p e}end end
[ "call.add" ]
31,812
31,811
u300645821
ruby
p00095
gets;p [*$<].max_by{|s|a,b=s.split.map &:to_i;b*100+100-a}
gets;puts [*$<].max_by{|s|a,b=s.split.map &:to_i;b*100+100-a}
[ "call.function.change", "io.output.change" ]
32,017
32,018
u868447400
ruby
p00095
a=0;v=0; gets.to_i.times do line=gets x,y=line.split.map(&:to_i) if y>v then a=x;v=y elsif y=v then if x<a then a=x end end end print a," ",v,"\n"
a=0;v=-1; gets.to_i.times do line=gets x,y=line.split.map(&:to_i) if y>v then a=x;v=y elsif y==v then if x<a then a=x end end end print a," ",v,"\n"
[ "assignment.value.change", "expression.operation.unary.add", "expression.operation.compare.replace.add", "assignment.replace.remove", "misc.typo" ]
32,025
32,026
u925831343
ruby
p00095
a=0;v=-1; gets.to_i.times do line=gets x,y=line.split.map(&:to_i) if y>v then a=x;v=y elsif y=v then if x<a then a=x end end end print a," ",v,"\n"
a=0;v=-1; gets.to_i.times do line=gets x,y=line.split.map(&:to_i) if y>v then a=x;v=y elsif y==v then if x<a then a=x end end end print a," ",v,"\n"
[ "expression.operation.compare.replace.add", "assignment.replace.remove", "misc.typo" ]
32,027
32,026
u925831343
ruby
p00095
def main(input = STDIN) maxv = 0 maxa = 1 / 0.0 input.gets.to_i.times do a, v = input.gets.split(" ").map(&:to_i) maxv, maxa = v, a if maxv < v or (maxv == v and maxa <= a) end puts "#{maxa} #{maxv}" end main
def main(input = STDIN) maxv = 0 maxa = 1 / 0.0 input.gets.to_i.times do a, v = input.gets.split(" ").map(&:to_i) maxv, maxa = v, a if maxv < v or (maxv == v and maxa > a) end puts "#{maxa} #{maxv}" end main
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
32,028
32,029
u514597327
ruby
p00095
l = [] gets.to_i.times { l << gets.split.map(&:to_i) } puts l.sort_by{ |v| [-v[1], v[0]] }.join(" ")
l = [] gets.to_i.times { l << gets.split.map(&:to_i) } puts l.sort_by{ |v| [-v[1], v[0]] }[0].join(" ")
[]
32,030
32,031
u811434779
ruby
p00097
L = 100 @memo = Array.new(9) {Array.new(101) {[]}} def solve(num, start, sum) return 0 if sum <= 0 or start > L return (sum <= L) ? 1 : 0 if num == 1 a = @memo[num - 1][start][sum] return a if a co = 0 lim = [L, sum].min (start..lim).each do |i| co += solve(num - 1, i + 1, sum - i) end @memo[num - 1][start][sum] = co end until (a = $<.gets.split.map(&:to_i)) == [0, 0] puts solve(a.first, 0, a.last) end
L = 100 @memo = Array.new(9) {Array.new(101) {[]}} def solve(num, start, sum) return 0 if sum < 0 or start > L return (start <= sum and sum <= L) ? 1 : 0 if num == 1 a = @memo[num - 1][start][sum] return a if a co = 0 lim = [L, sum].min (start..lim).each do |i| co += solve(num - 1, i + 1, sum - i) end @memo[num - 1][start][sum] = co end until (a = $<.gets.split.map(&:to_i)) == [0, 0] puts solve(a.first, 0, a.last) end
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
32,392
32,393
u864617427
ruby
p00097
L = 100 @memo = Array.new(9) {Array.new(101) {[]}} def solve(num, start, sum) return 0 if sum <= 0 or start > L return (sum <= L) ? 1 : 0 if num == 1 a = @memo[num - 1][start][sum] return a if a co = 0 lim = [L, (2 * sum - num ** 2 + num) / (2 * num)].min (start..lim).each do |i| co += solve(num - 1, i + 1, sum - i) end @memo[num - 1][start][sum] = co end until (a = $<.gets.split.map(&:to_i)) == [0, 0] puts solve(a.first, 0, a.last) end
L = 100 @memo = Array.new(9) {Array.new(101) {[]}} def solve(num, start, sum) return 0 if sum < 0 or start > L return (start <= sum and sum <= L) ? 1 : 0 if num == 1 a = @memo[num - 1][start][sum] return a if a co = 0 lim = [L, (2 * sum - num ** 2 + num) / (2 * num)].min (start..lim).each do |i| co += solve(num - 1, i + 1, sum - i) end @memo[num - 1][start][sum] = co end until (a = $<.gets.split.map(&:to_i)) == [0, 0] puts solve(a.first, 0, a.last) end
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
32,395
32,396
u864617427
ruby
p00097
L = 100 @memo = Array.new(9) {Array.new(101) {[]}} def solve(num, start, sum) return 0 if sum <= 0 or start > L return (start <= sum and sum <= L) ? 1 : 0 if num == 1 a = @memo[num - 1][start][sum] return a if a co = 0 lim = [L, (2 * sum - num ** 2 + num) / (2 * num)].min (start..lim).each do |i| co += solve(num - 1, i + 1, sum - i) end @memo[num - 1][start][sum] = co end until (a = $<.gets.split.map(&:to_i)) == [0, 0] puts solve(a.first, 0, a.last) end
L = 100 @memo = Array.new(9) {Array.new(101) {[]}} def solve(num, start, sum) return 0 if sum < 0 or start > L return (start <= sum and sum <= L) ? 1 : 0 if num == 1 a = @memo[num - 1][start][sum] return a if a co = 0 lim = [L, (2 * sum - num ** 2 + num) / (2 * num)].min (start..lim).each do |i| co += solve(num - 1, i + 1, sum - i) end @memo[num - 1][start][sum] = co end until (a = $<.gets.split.map(&:to_i)) == [0, 0] puts solve(a.first, 0, a.last) end
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
32,397
32,396
u864617427
ruby
p00099
hash = Hash.new(0) min_a, max_v = Float::INFINITY, 0 n, q = gets.chomp.split.map(&:to_i) q.times do a, v = gets.chomp.split.map(&:to_i) hash[a] += v if v > 0 if hash[a] > max_v max_v = hash[a] min_a = a elsif hash[a] == max_v max_a = [a, min_a].min end else if a == min_a order = hash.sort do |(k1, v1), (k2, v2)| if v1 == v2 k1 <=> k2 else v2 <=> v1 end end min_a, max_v = order.first[0], order.first[1] end end puts [min_a, max_v].join(' ') end
hash = Hash.new(0) min_a, max_v = Float::INFINITY, -Float::INFINITY n, q = gets.chomp.split.map(&:to_i) q.times do a, v = gets.chomp.split.map(&:to_i) hash[a] += v if v > 0 if hash[a] > max_v max_v = hash[a] min_a = a elsif hash[a] == max_v min_a = [a, min_a].min end else if a == min_a order = hash.sort do |(k1, v1), (k2, v2)| if v1 == v2 k1 <=> k2 else v2 <=> v1 end end min_a, max_v = order.first[0], order.first[1] end end puts [min_a, max_v].join(' ') end
[ "assignment.value.change", "assignment.variable.change", "identifier.change" ]
32,877
32,878
u024281398
ruby
p00100
while true hash = Hash.new n = gets.to_i #???????????° break if n == 0 for r in 0...n do line = gets.chomp! line = line.split no = line[0].to_i #???????????? unitPrice = line[1].to_i #????£??????? quantity = line[2].to_i #?£??????°??? total = unitPrice * quantity #?°??¨? if hash.key?(no) total += hash[no] end hash[no] = total end if hash.select{|key, val| val >= 1000000}.empty? p "NA" else hash.each{ |key, val| if val >= 1000000 p key end } end end
while true hash = Hash.new n = gets.to_i #???????????° break if n == 0 for r in 0...n do line = gets.chomp! line = line.split no = line[0].to_i #???????????? unitPrice = line[1].to_i #????£??????? quantity = line[2].to_i #?£??????°??? total = unitPrice * quantity #?°??¨? if hash.key?(no) total += hash[no] end hash[no] = total end if hash.select{|key, val| val >= 1000000}.empty? puts "NA" else hash.each{ |key, val| if val >= 1000000 p key end } end end
[ "call.function.change", "io.output.change" ]
33,551
33,552
u290971603
ruby
p00100
loop do n = gets.to_i break if n.zero? totals = Hash.new(0) n.times do e, p, q = gets.split.map(&:to_i) totals[e] += p * q end employees = totals.select { |_, total| total >= 1_000_000 }.keys.sort if employees.empty? puts 'NA' else puts employees.sort.join("\n") end end
loop do n = gets.to_i break if n.zero? totals = Hash.new(0) n.times do e, p, q = gets.split.map(&:to_i) totals[e] += p * q end employees = totals.select { |_, total| total >= 1_000_000 }.keys if employees.empty? puts 'NA' else puts employees.join("\n") end end
[ "call.remove" ]
33,560
33,561
u139670451
ruby
p00100
while n = gets.chomp.to_i break if n.zero? sales = Hash.new{0} n.times do e, p, q = gets.chomp.split.map(&:to_i) sales[e] += p * q end achieved = sales.select{|k, v| v >= 1_000_000} achieved.each{|k, v| puts k} puts 'NA' unless achieved.empty? end
while n = gets.chomp.to_i break if n.zero? sales = Hash.new{0} n.times do e, p, q = gets.chomp.split.map(&:to_i) sales[e] += p * q end achieved = sales.select{|k, v| v >= 1_000_000} achieved.each{|k, v| puts k} puts 'NA' if achieved.empty? end
[]
33,562
33,563
u670581076
ruby
p00100
loop do n = gets.to_i break if n.zero? dataset = Hash.new dataset.default = 0 n.times do id, selling_price, quantity = gets.chomp.split.map(&:to_i) dataset[id] += selling_price * quantity end satisfying_id = dataset.select{|id, sales| v >= 1000000 }.keys.join(?\n) puts (satisfying_id.empty? ? "NA" : satisfying_id.sort) end
loop do n = gets.to_i break if n.zero? dataset = Hash.new dataset.default = 0 n.times do id, selling_price, quantity = gets.chomp.split.map(&:to_i) dataset[id] += selling_price * quantity end satisfying_id = dataset.select{|id, sales| sales >= 1000000 }.keys.join(?\n) puts (satisfying_id.empty? ? "NA" : satisfying_id) end
[ "assignment.value.change", "identifier.change", "expression.operation.binary.change", "call.remove" ]
33,568
33,569
u881491942
ruby
p00100
loop do n = gets.to_i break if n.zero? dataset = Hash.new dataset.default = 0 n.times do id, selling_price, quantity = gets.chomp.split.map(&:to_i) dataset[id] += selling_price * quantity end satisfying_id = dataset.select{|id, sales| sales >= 1000000 }.keys.join(?\n) puts (satisfying_id.empty? ? "NA" : satisfying_id.sort) end
loop do n = gets.to_i break if n.zero? dataset = Hash.new dataset.default = 0 n.times do id, selling_price, quantity = gets.chomp.split.map(&:to_i) dataset[id] += selling_price * quantity end satisfying_id = dataset.select{|id, sales| sales >= 1000000 }.keys.join(?\n) puts (satisfying_id.empty? ? "NA" : satisfying_id) end
[ "call.remove" ]
33,570
33,569
u881491942
ruby
p00103
gets.to_i.times{r=o=s=0 (c=gets[1];c<?O?(r+=1):c<?U?(s+=r+1;r=0):o+=1)while o<3 p s+r-3}
gets.to_i.times{r=o=s=0 (c=gets[1];c<?O?(r+=1):c<?U?(s+=r+1;r=0):o+=1)while o<3 p r<3?s:s+r-3}
[ "call.arguments.change" ]
33,664
33,665
u198069342
ruby
p00103
class BaseBall def initialize @first=false @second=false @third=false @out=0 end def hit if @third then point=1 else point=0 end @third = false @third = true if @second @second = true if @first @first = true return point end def homerun point= [@first,@second,@third].select{|x| x}.length + 1 @first,@second,@third =false return point end def out @out += 1 if @out>= 3 then @out=0 return true else return false end end end if false then fh=STDIN else fh=open("in0103.txt") end n= fh.gets.chomp.to_i 0.upto(n-1) { |i| point=0 bb = BaseBall.new while fh.gets do s = $_.chomp if s=="HIT" then point += bb.hit elsif s=="HOMERUN" then point += bb.homerun elsif s=="OUT" then if bb.out then puts point break end end end }
class BaseBall def initialize @first=false @second=false @third=false @out=0 end def hit if @third then point=1 else point=0 end @third = false @third = true if @second @second = true if @first @first = true return point end def homerun point= [@first,@second,@third].select{|x| x}.length + 1 @first,@second,@third =false return point end def out @out += 1 if @out>= 3 then @out=0 return true else return false end end end if true then fh=STDIN else fh=open("in0103.txt") end n= fh.gets.chomp.to_i 0.upto(n-1) { |i| point=0 bb = BaseBall.new while fh.gets do s = $_.chomp if s=="HIT" then point += bb.hit elsif s=="HOMERUN" then point += bb.homerun elsif s=="OUT" then if bb.out then puts point break end end end }
[ "misc.opposites", "control_flow.branch.if.condition.change" ]
33,668
33,669
u032662562
ruby
p00103
left=gets.to_i out,runner,score=0,0,0 while left>0 judge=gets.chomp case judge when "HIT" then runner+=1 if runner>3 then runner-=1 score+=1 end when "OUT" then out+=1 if out>=3 then puts score runner,score=0,0 left-=1 end when "HOMERUN" then score+=(runner+1) runner=0 end end
left=gets.to_i out,runner,score=0,0,0 while left>0 judge=gets.chomp case judge when "HIT" then runner+=1 if runner>3 then runner-=1 score+=1 end when "OUT" then out+=1 if out>=3 then puts score runner,score,out=0,0,0 left-=1 end when "HOMERUN" then score+=(runner+1) runner=0 end end
[]
33,670
33,671
u461552210
ruby
p00101
n = gets puts $_.gsub("Hoshiro", "Hoshina") while gets
n = gets puts $_.gsub("Hoshino", "Hoshina") while gets
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
33,901
33,902
u797180951
ruby
p00101
n = gets.to_i n.times do line = gets.chomp! puts line.gsub('Hosino', 'Hoshina') end
n = gets.to_i n.times do line = gets.chomp! puts line.gsub('Hoshino', 'Hoshina') end
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
33,905
33,906
u888227825
ruby
p00101
#繰り返し回数 count = gets.to_i count.times do #入力された値の"Hoshino"を"Hoshina"に置き換えて表示 p gets.gsub("Hoshino","Hoshina") end
#繰り返し回数 count = gets.to_i count.times do #入力された値の"Hoshino"を"Hoshina"に置き換えて表示 puts gets.gsub("Hoshino","Hoshina") end
[ "call.function.change", "io.output.change" ]
33,917
33,916
u770686467
ruby
p00101
gets.to_i.times { p gets.chomp.gsub("Hoshino", "Hoshina") }
gets.to_i.times { puts gets.chomp.gsub("Hoshino", "Hoshina") }
[ "call.function.change", "io.output.change" ]
33,928
33,929
u881491942
ruby
p00102
num=[] while gets x=[] y=[] z=0 s=$_.to_i break if (s==0) s.times do |i| x[i]=0 num<<gets.chomp.split(nil).map(&:to_i) x[i]=num[i].inject(:+) z+=x[i] end s.times do |i| y[i]=0 s.times do |j| y[i]+=num[j][i] end end s.times do |i| s.times do |j| printf("%5d",num[i][j]) end printf("%5d\n",x[i]) end s.times do |i| printf("%5d",y[i]) end printf("%5d\n",z) end
loop do num=[] x=[] y=[] z=0 s=gets.to_i break if (s==0) s.times do |i| x[i]=0 num<<gets.chomp.split(nil).map(&:to_i) x[i]=num[i].inject(:+) z+=x[i] end s.times do |i| y[i]=0 s.times do |j| y[i]+=num[j][i] end end s.times do |i| s.times do |j| printf("%5d",num[i][j]) end printf("%5d\n",x[i]) end s.times do |i| printf("%5d",y[i]) end printf("%5d\n",z) end
[ "assignment.value.change" ]
34,203
34,204
u287407095
ruby
p00102
num=[] while true x=[] y=[] z=0 s=gets.to_i break if (s==0) s.times do |i| x[i]=0 num<<gets.chomp.split(nil).map(&:to_i) x[i]=num[i].inject(:+) z+=x[i] end s.times do |i| y[i]=0 s.times do |j| y[i]+=num[j][i] end end s.times do |i| s.times do |j| printf("%5d",num[i][j]) end printf("%5d\n",x[i]) end s.times do |i| printf("%5d",y[i]) end printf("%5d\n",z) end
loop do num=[] x=[] y=[] z=0 s=gets.to_i break if (s==0) s.times do |i| x[i]=0 num<<gets.chomp.split(nil).map(&:to_i) x[i]=num[i].inject(:+) z+=x[i] end s.times do |i| y[i]=0 s.times do |j| y[i]+=num[j][i] end end s.times do |i| s.times do |j| printf("%5d",num[i][j]) end printf("%5d\n",x[i]) end s.times do |i| printf("%5d",y[i]) end printf("%5d\n",z) end
[]
34,205
34,204
u287407095
ruby
p00102
num=[] loop do x=[] y=[] z=0 s=gets.to_i break if (s==0) s.times do |i| x[i]=0 num<<gets.chomp.split(nil).map(&:to_i) x[i]=num[i].inject(:+) z+=x[i] end s.times do |i| y[i]=0 s.times do |j| y[i]+=num[j][i] end end s.times do |i| s.times do |j| printf("%5d",num[i][j]) end printf("%5d\n",x[i]) end s.times do |i| printf("%5d",y[i]) end printf("%5d\n",z) end
loop do num=[] x=[] y=[] z=0 s=gets.to_i break if (s==0) s.times do |i| x[i]=0 num<<gets.chomp.split(nil).map(&:to_i) x[i]=num[i].inject(:+) z+=x[i] end s.times do |i| y[i]=0 s.times do |j| y[i]+=num[j][i] end end s.times do |i| s.times do |j| printf("%5d",num[i][j]) end printf("%5d\n",x[i]) end s.times do |i| printf("%5d",y[i]) end printf("%5d\n",z) end
[]
34,206
34,204
u287407095
ruby
p00102
num=[] loop do x=[] y=[] z=0 s=gets.to_i break if (s==0) s.times do |i| x[i]=0 num<<gets.chomp.split(nil).map(&:to_i) x[i]=num[i].inject(:+) z+=x[i] end s.times do |i| y[i]=0 s.times do |j| y[i]+=num[j][i] end end s.times do |i| s.times do |j| printf("%5d",num[i][j]) end printf("%5d\n",x[i]) end s.times do |i| printf("%5d ",y[i]) end printf("%5d\n",z) end
loop do num=[] x=[] y=[] z=0 s=gets.to_i break if (s==0) s.times do |i| x[i]=0 num<<gets.chomp.split(nil).map(&:to_i) x[i]=num[i].inject(:+) z+=x[i] end s.times do |i| y[i]=0 s.times do |j| y[i]+=num[j][i] end end s.times do |i| s.times do |j| printf("%5d",num[i][j]) end printf("%5d\n",x[i]) end s.times do |i| printf("%5d",y[i]) end printf("%5d\n",z) end
[]
34,208
34,204
u287407095
ruby
p00104
loop do w, h = gets.chomp.split.map(&:to_i) break if [w, h].all?(&:zero?) tile_map = Array.new h.times do |i| tile_map[i] = gets.chomp.split('') end x = y = 0 tile_already_arrived = Array.new h.times { tile_already_arrived << Array.new(w, false) } is_loop = false while true tile = tile_map[y][x] if tile_already_arrived[y][x] == true is_loop = true break else tile_already_arrived[y][x] = true case tile when '>' x += 1 when '<' x -= 1 when 'v' y += 1 when '^' y -= 1 when '.' goal = [x,y] break end end end if is_loop puts "LOOP" else puts "#{goal[0]} #{goal[1]}" end end
loop do h, w = gets.chomp.split.map(&:to_i) break if [w, h].all?(&:zero?) tile_map = Array.new h.times do |i| tile_map[i] = gets.chomp.split('') end x = y = 0 tile_already_arrived = Array.new h.times { tile_already_arrived << Array.new(w, false) } is_loop = false while true tile = tile_map[y][x] if tile_already_arrived[y][x] == true is_loop = true break else tile_already_arrived[y][x] = true case tile when '>' x += 1 when '<' x -= 1 when 'v' y += 1 when '^' y -= 1 when '.' goal = [x,y] break end end end if is_loop puts "LOOP" else puts "#{goal[0]} #{goal[1]}" end end
[]
34,251
34,252
u881491942
ruby
p00104
loop do h, w = gets.chomp.split.map(&:to_i) break if [h, w].all?(&:zero?) tile_map = tile_already_arrived = Array.new h.times do tile_map << gets.chomp.split('') tile_already_arrived << Array.new(w, false) end x = y = 0 while true tile_present = tile_map[y][x] if tile_already_arrived[y][x] == true goal = "LOOP" break else tile_already_arrived[y][x] = true case tile_present when '>' x += 1 when '<' x -= 1 when 'v' y += 1 when '^' y -= 1 when '.' goal = "#{x} #{y}" break end end end puts goal end
loop do h, w = gets.chomp.split.map(&:to_i) break if [h, w].all?(&:zero?) tile_map = Array.new tile_already_arrived = Array.new h.times do tile_map << gets.chomp.split('') tile_already_arrived << Array.new(w, false) end x = y = 0 while true tile_present = tile_map[y][x] if tile_already_arrived[y][x] == true goal = "LOOP" break else tile_already_arrived[y][x] = true case tile_present when '>' x += 1 when '<' x -= 1 when 'v' y += 1 when '^' y -= 1 when '.' goal = "#{x} #{y}" break end end end puts goal end
[ "call.add" ]
34,253
34,254
u881491942
ruby
p00104
loop do h, w = gets.chomp.split.map(&:to_i) break if [h, w].all?(&:zero?) tile_map = tile_already_arrived = Array.new h.times do tile_map << gets.chomp.split('') tile_already_arrived << Array.new(w, false) end x = y = 0 while true tile_present = tile_map[y][x] if tile_already_arrived[y][x] == true goal = "LOOP" break else tile_already_arrived[y][x] = true case tile_present when '>' x += 1 when '<' x -= 1 when 'v' y += 1 when '^' y -= 1 when '.' goal = "#{x} #{y}" break end end end puts goal end
loop do h, w = gets.chomp.split.map(&:to_i) break if [h, w].all?(&:zero?) tile_map = Array.new tile_already_arrived = Array.new h.times do tile_map << gets.chomp.split('') tile_already_arrived << Array.new(w, false) end x = y = 0 while true tile_present = tile_map[y][x] if tile_already_arrived[y][x] == true goal = "LOOP" break else tile_already_arrived[y][x] = true case tile_present when '>' x += 1 when '<' x -= 1 when 'v' y += 1 when '^' y -= 1 when '.' goal = "#{x} #{y}" break end end end puts goal end
[ "call.add" ]
34,253
34,255
u881491942
ruby
p00105
index=Hash.new{|word,page| word[page] = []} while line =gets do word,page= line.split(" ") page =page.to_i index[word]<<page end p index index.each{|word,page|page.sort!} index2=index.sort index2.each{|key,value| puts key puts value.join(" ") }
index=Hash.new{|word,page| word[page] = []} while line =gets do word,page= line.split(" ") page =page.to_i index[word]<<page end index.each{|word,page|page.sort!} index2=index.sort index2.each{|key,value| puts key puts value.join(" ") }
[ "call.remove" ]
34,380
34,381
u534464795
ruby
p00105
cat rb.rb hash = Hash.new([]) while true do line = gets break if line == nil line.chomp word, page = line.split(' ') hash[word] += [page.to_i] end arr = hash.sort arr.each do |w| puts w[0] w[1].sort! puts w[1].join(' ') end
hash = Hash.new([]) while true do line = gets break if line == nil line.chomp word, page = line.split(' ') hash[word] += [page.to_i] end arr = hash.sort arr.each do |w| puts w[0] w[1].sort! puts w[1].join(' ') end
[ "call.remove" ]
34,382
34,383
u879497299
ruby
p00121
require 'pry' def to_xy(str, target) str.chars.each_with_index do |s, i| if target == s.to_i x = i%4 y = i < 4 ? 0 : 1 return x, y, i end end end def move_zero(str, mx, my) zx, zy, zi = to_xy(str, 0) (1..7).each do |i| sx, sy, si = to_xy(str, i) if (zx + mx) == sx and (zy + my) == sy ns = str.dup ns[zi], ns[si] = ns[si], ns[zi] return ns end end end rule = Struct.new('Rule', :can_move?, :move) rules = [ rule.new(lambda { |str| x, _, _ = to_xy(str, 0); x <= 2 }, lambda { |str| move_zero(str, 1, 0) }), rule.new(lambda { |str| _, y, _ = to_xy(str, 0); y == 0 }, lambda { |str| move_zero(str, 0, 1) }), rule.new(lambda { |str| x, _, _ = to_xy(str, 0); x >= 1 }, lambda { |str| move_zero(str, -1, 0) }), rule.new(lambda { |str| _, y, _ = to_xy(str, 0); y == 1 }, lambda { |str| move_zero(str, 0, -1) }) ] goal = '01234567' map_list = [goal] answers = {goal => 0} loop do search_map = map_list.shift break unless search_map rules.each do |rule| next unless rule.can_move?.call(search_map) next_map = rule.move.call(search_map) next if answers[next_map] answers[next_map.to_s] = answers[search_map] + 1 map_list.push(next_map) end end while s = gets puts answers[s.chomp.split.join] end
def to_xy(str, target) str.chars.each_with_index do |s, i| if target == s.to_i x = i%4 y = i < 4 ? 0 : 1 return x, y, i end end end def move_zero(str, mx, my) zx, zy, zi = to_xy(str, 0) (1..7).each do |i| sx, sy, si = to_xy(str, i) if (zx + mx) == sx and (zy + my) == sy ns = str.dup ns[zi], ns[si] = ns[si], ns[zi] return ns end end end rule = Struct.new('Rule', :can_move?, :move) rules = [ rule.new(lambda { |str| x, _, _ = to_xy(str, 0); x <= 2 }, lambda { |str| move_zero(str, 1, 0) }), rule.new(lambda { |str| _, y, _ = to_xy(str, 0); y == 0 }, lambda { |str| move_zero(str, 0, 1) }), rule.new(lambda { |str| x, _, _ = to_xy(str, 0); x >= 1 }, lambda { |str| move_zero(str, -1, 0) }), rule.new(lambda { |str| _, y, _ = to_xy(str, 0); y == 1 }, lambda { |str| move_zero(str, 0, -1) }) ] goal = '01234567' map_list = [goal] answers = {goal => 0} loop do search_map = map_list.shift break unless search_map rules.each do |rule| next unless rule.can_move?.call(search_map) next_map = rule.move.call(search_map) next if answers[next_map] answers[next_map.to_s] = answers[search_map] + 1 map_list.push(next_map) end end while s = gets puts answers[s.chomp.split.join] end
[ "call.remove" ]
37,128
37,129
u708217907
ruby
p00127
def maje_table i = 0 j = 0 table = Array.new(6) table.map!{Array.new(5)} "a".upto("z") do |c| table[i][j] = c j += 1 i += 1 if j == 5 j = 0 if j == 5 end table[5][1] = '.' table[5][2] = '?' table[5][3] = '!' table[5][4] = ' ' table end $table = make_table readlines.each do |input| message = input.chomp if message.size.odd? puts "NA" next end message_int = [] message.chars.map{|x| x.to_i-1}.each_slice(2){ |x| message_int << x } if message_int.map{ |cons| 0 <= cons.first && cons.first <= 5 && 0 <= cons.last && cons.last <= 4 }.include?(false) puts "NA" next end message_int.each { |set| print $table[set.first][set.last] } puts "" end
def make_table i = 0 j = 0 table = Array.new(6) table.map!{Array.new(5)} "a".upto("z") do |c| table[i][j] = c j += 1 i += 1 if j == 5 j = 0 if j == 5 end table[5][1] = '.' table[5][2] = '?' table[5][3] = '!' table[5][4] = ' ' table end $table = make_table readlines.each do |input| message = input.chomp if message.size.odd? puts "NA" next end message_int = [] message.chars.map{|x| x.to_i-1}.each_slice(2){ |x| message_int << x } if message_int.map{ |cons| 0 <= cons.first && cons.first <= 5 && 0 <= cons.last && cons.last <= 4 }.include?(false) puts "NA" next end message_int.each { |set| print $table[set.first][set.last] } puts "" end
[ "identifier.change" ]
37,583
37,584
u881491942
ruby
p00135
n = gets.to_i t = []*n 0.upto(n-1) {|i| t[i] = gets.chomp.split(/:/).map(&:to_i)} 0.upto(n-1) do |i| a,b = t[i] long = b * 6 short = a * 30 + b.to_f / 2 r = (long - short).abs r = 180 - r if r > 180 case r when 0...30 puts "alert" when 30...90 puts "warning" when 90..180 puts "safe" end end
n = gets.to_i t = []*n 0.upto(n-1) {|i| t[i] = gets.chomp.split(/:/).map(&:to_i)} 0.upto(n-1) do |i| a,b = t[i] long = b * 6 short = a * 30 + b.to_f / 2 r = (long - short).abs r = 360 - r if r > 180 case r when 0...30 puts "alert" when 30...90 puts "warning" when 90..180 puts "safe" end end
[ "literal.number.integer.change", "assignment.value.change", "expression.operation.binary.change" ]
38,074
38,075
u329400409
ruby
p00135
n = gets.chomp.to_i n.times do h, m = gets.chomp.split(':').map(&:to_f) diff = (h * 30 + m * 0.5 - m * 6).abs diff = 360 - diff if diff > 180 puts diff if diff < 30 puts :alert elsif diff < 90 puts :warning else puts :safe end end
n = gets.chomp.to_i n.times do h, m = gets.chomp.split(':').map(&:to_f) diff = (h * 30 + m * 0.5 - m * 6).abs diff = 360 - diff if diff > 180 if diff < 30 puts :alert elsif diff < 90 puts :warning else puts :safe end end
[ "call.remove" ]
38,076
38,077
u024281398
ruby
p00141
puts ("1\n"..gets).map{n=gets.to_i n<2?"#\n":n<3?"# \n"*2:(a=[?#*n+?\n]+(2..n).map{?#+" "*(n-2)+"#\n"} c=i=j=n-1 d=[[1,0],[0,-1],[-1,0],[0,1]] (c=0;(x,y),_=d.rotate!;(c+=1;a[i+=x][j+=y]=?#)while a[i+x*2][j+y*2]<?#)while c>1 a*"")}*?\n
puts ("1\n"..gets).map{n=gets.to_i n<2?"#\n":n<3?"##\n# \n":(a=[?#*n+?\n]+(2..n).map{?#+" "*(n-2)+"#\n"} c=i=j=n-1 d=[[1,0],[0,-1],[-1,0],[0,1]] (c=0;(x,y),_=d.rotate!;(c+=1;a[i+=x][j+=y]=?#)while a[i+x*2][j+y*2]<?#)while c>1 a*"")}*?\n
[ "literal.string.change", "call.arguments.change", "expression.operation.binary.change", "io.output.change", "expression.operation.binary.remove" ]
38,230
38,231
u198069342
ruby
p00148
while gets tmp = ($_.to_i) % 39 puts "3c%02d" % (tmp == 0 ? 39 : tmp) end
while gets tmp = ($_.to_i) % 39 puts "3C%02d" % (tmp == 0 ? 39 : tmp) end
[ "literal.string.change", "literal.string.case.change", "call.arguments.change", "expression.operation.binary.change" ]
38,593
38,594
u814658648
ruby
p00150
require 'prime' m = 10000 cache = Prime.each(m).each_cons(2).select {|a,b| b-a == 2 }.reverse while (n = gets.to_i)!=0 p1,q1 = cache.bsearch {|_,q| n > q } puts "#{p1} #{q1}" end
require 'prime' m = 10000 cache = Prime.each(m).each_cons(2).select {|a,b| b-a == 2 }.reverse while (n = gets.to_i)!=0 p1,q1 = cache.bsearch {|_,q| n >= q } puts "#{p1} #{q1}" end
[ "expression.operator.compare.change", "assignment.value.change", "expression.operation.binary.change" ]
38,939
38,940
u645368411
ruby
p00150
require 'prime' twin_prime = Prime.each(10000).each_cons(2).select{ |p, q| q - p == 2} loop do n = gets.to_i break if n.zero? ans = twin_prime.select{ |twin| twin.last < n }.last puts ans.join(' ') end
require 'prime' twin_prime = Prime.each(10000).each_cons(2).select{ |p, q| q - p == 2} loop do n = gets.to_i break if n.zero? ans = twin_prime.select{ |twin| twin.last <= n }.last puts ans.join(' ') end
[ "expression.operator.compare.change", "assignment.value.change", "expression.operation.binary.change" ]
38,941
38,942
u881491942
ruby
p00160
criteria = [ [60, 2, 600], [80, 5, 800], [100, 10, 1000], [120, 15, 1200], [140, 20, 1400], [160, 25, 1600] ] while line = gets n = line.chomp.to_i break if n == 0 fee = 0 n.times do x, y, h, w = gets.chomp.split.map(&:to_i) criteria.each do |a| if [x, y, h].max <= a[0] && w <= a[1] fee += a[2] break end end end puts fee end
criteria = [ [60, 2, 600], [80, 5, 800], [100, 10, 1000], [120, 15, 1200], [140, 20, 1400], [160, 25, 1600] ] while line = gets n = line.chomp.to_i break if n == 0 fee = 0 n.times do x, y, h, w = gets.chomp.split.map(&:to_i) criteria.each do |a| if x + y + h <= a[0] && w <= a[1] fee += a[2] break end end end puts fee end
[ "control_flow.branch.if.condition.change", "call.remove" ]
39,201
39,202
u024281398
ruby
p00168
def rec(n, current) if @dp[current] != -1 return @dp[current] end if current == n 1 elsif current > n 0 else @dp[current] = rec(n, current + 1) + rec(n, current + 2) + rec(n, current + 3) end end def solve(n) @dp = Array.new(34, -1) sum = rec(n, 0) result = ( (sum / 10) + 365 ) / 365 end def main STDIN.each_line{|line| n = line.to_i puts solve n if n == 0 break end } end main
def rec(n, current) if @dp[current] != -1 return @dp[current] end if current == n 1 elsif current > n 0 else @dp[current] = rec(n, current + 1) + rec(n, current + 2) + rec(n, current + 3) end end def solve(n) @dp = Array.new(34, -1) sum = rec(n, 0) result = ( (sum / 10) + 365 ) / 365 end def main STDIN.each_line{|line| n = line.to_i if n == 0 break end puts solve n } end main
[ "call.remove", "call.add" ]
39,682
39,683
u164672217
ruby
p00168
$kannondou = [0, 1, 2, 4] $size = $kannondou.size def count(n) while $size < n $kannondou[$size] = $kannondou[$size-1] + $kannondou[$size-2] + $kannondou[$size-3] $size += 1 end $kannondou[n] end while n = gets.to_i break if n.zero? puts count(n) / 3650 + 1 end
$kannondou = [0, 1, 2, 4] $size = $kannondou.size def count(n) while $size <= n $kannondou[$size] = $kannondou[$size-1] + $kannondou[$size-2] + $kannondou[$size-3] $size += 1 end $kannondou[n] end while n = gets.to_i break if n.zero? puts count(n) / 3650 + 1 end
[ "expression.operator.compare.change", "expression.operation.binary.change" ]
39,685
39,686
u881491942
ruby
p00168
Moves = [1,2,3] MaxStep = 30 def solve dp = Array.new(MaxStep + 1, 0) dp[0] = 1 for step in 1...MaxStep Moves.each do |m| break if step - m < 0 dp[step] += dp[step - m] end end dp end result = solve while (n = $stdin.gets.to_i) != 0 printf "%d\n", (result[n].to_f / 3650.to_f).ceil end
Moves = [1,2,3] MaxStep = 30 def solve dp = Array.new(MaxStep + 1, 0) dp[0] = 1 for step in 1..MaxStep Moves.each do |m| break if step - m < 0 dp[step] += dp[step - m] end end dp end result = solve while (n = $stdin.gets.to_i) != 0 printf "%d\n", (result[n].to_f / 3650.to_f).ceil end
[]
39,687
39,688
u985809245
ruby
p00196
loop{ n=gets.to_i; exit if n==0; [*1..n].map{s,*a=gets.split;t=0;a.map{|b|b=b.to_i;t+=b==0 ? 2*n : b==1 ? -1 : 0};[-t,s]}.sort.map{|a|puts a[1]} }
loop{ n=gets.to_i; exit if n==0; [*1..n].map{|i|s,*a=gets.split;t=0;a.map{|b|b=b.to_i;t+=b==0 ? 2*n : b==1 ? -1 : 0};[-t,i,s]}.sort.map{|a|puts a[2]} }
[ "literal.array.change", "literal.number.integer.change", "variable_access.subscript.index.change", "call.arguments.change", "io.output.change" ]
40,917
40,918
u868447400
ruby
p00191
def solve trans,m,n prev = Array.new(n,1.0) (m-1).times do cur = Array.new(n,0) n.times do |i| n.times do |j| cur[i] = [cur[i], prev[j]*trans[j][i]].max end end cur,prev = prev,cur end prev.max end loop do n,m = gets.chomp.split.map{|i|i.to_i} break if n==0 trans = [] n.times do a = gets.chomp.split.map{|i|i.to_f} trans << a end puts "%.5f" % solve(trans,m,n) end
def solve trans,m,n prev = Array.new(n,1.0) (m-1).times do cur = Array.new(n,0) n.times do |i| n.times do |j| cur[i] = [cur[i], prev[j]*trans[j][i]].max end end cur,prev = prev,cur end prev.max end loop do n,m = gets.chomp.split.map{|i|i.to_i} break if n==0 trans = [] n.times do a = gets.chomp.split.map{|i|i.to_f} trans << a end puts "%.2f" % solve(trans,m,n) end
[ "literal.string.change", "call.arguments.change", "expression.operation.binary.change", "io.output.change" ]
41,733
41,734
u553881259
ruby