Skip to content

Instantly share code, notes, and snippets.

@mura303
Created May 29, 2017 22:25
Show Gist options
  • Select an option

  • Save mura303/8d61d30c6280e7e7122940dd7adbc814 to your computer and use it in GitHub Desktop.

Select an option

Save mura303/8d61d30c6280e7e7122940dd7adbc814 to your computer and use it in GitHub Desktop.
#!ruby
inputnum = gets.to_i
inputnum.times do |case_id|
(s, k_str) = gets.split
k = k_str.to_i
count = 0
result = nil
(s.length-k+1).times do |i|
if s[i] == ?-
count += 1
k.times do |j|
if s[i+j] == ?-
s[i+j] = ?+
else
s[i+j] = ?-
end
end
end
end
if s.index(?-)
result = "IMPOSSIBLE"
else
result = count.to_s
end
puts "Case ##{case_id+1}: #{result}"
end
#!ruby
inputnum = gets.to_i
inputnum.times do |case_id|
(s, k_str) = gets.split
k = k_str.to_i
count = 0
result = nil
(s.length-k+1).times do |i|
if s[i] == ?-
count += 1
k.times do |j|
if s[i+j] == ?-
s[i+j] = ?+
else
s[i+j] = ?-
end
end
end
end
if s.index(?-)
result = "IMPOSSIBLE"
else
result = count.to_s
end
puts "Case ##{case_id+1}: #{result}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment