错过了昨晚史上前四题最简单的ABC,遗憾。在此奉上ABCD Ruby解。
A
s = gets.chomp
n = gets.to_i
puts s[n...-n]
B
h, w = gets.split.map(&:to_i)
num = Array.new(h) { Array.new(w, 0) }
for i in 0...h
for j in 0...w
cnt = 0
if i - 1 >= 0
cnt += 1
end
if i + 1 < h
cnt += 1
end
if j - 1 >= 0
cnt += 1
end
if j + 1 < w
cnt += 1
end
num[i][j] = cnt
end
end
num.each do |x|
puts x.join(" ")
end
C
s = gets.chomp.chars
total = 0
len = s.length
s.each_with_index do |s1, i|
if s1 == "C"
total += [len - i - 1, i].min + 1
end
end
puts total
D
require "sorted_containers"
x = gets.to_i
num = SortedContainers::SortedArray.new
num << x
q = gets.to_i
i = 1
q.times do
a, b = gets.split.map(&:to_i)
num << a
num << b
puts num[i]
i += 1
end