Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Last active September 11, 2016 16:58
Show Gist options
  • Save whatalnk/0495f8d6b253ef4eea8cc0462aa87ab5 to your computer and use it in GitHub Desktop.
Save whatalnk/0495f8d6b253ef4eea8cc0462aa87ab5 to your computer and use it in GitHub Desktop.
AtCoder ABC #045
# AC
a = gets.chomp.to_i
b = gets.chomp.to_i
h = gets.chomp.to_i
puts (a + b) * h / 2
# AC
a = gets.chomp.split("")
b = gets.chomp.split("")
c = gets.chomp.split("")
nex = a.shift
while true
if nex == "a" then
nxar = a
if nxar.empty? then
puts "A"
exit
end
elsif nex == "b" then
nxar = b
if nxar.empty? then
puts "B"
exit
end
elsif nex == "c" then
nxar = c
if nxar.empty? then
puts "C"
exit
end
end
nex = nxar.shift
end
# AC
s = gets.chomp.split("").map(&:to_i)
n = s.size
def base10(arr)
n = arr.size - 1
return n.downto(0).map{|x| arr[n - x]*10**x}.inject(:+)
end
if n == 1 then
puts s[0]
else
ans = [base10(s)]
idxar = (1..(n-1)).to_a
(1..(n-1)).each do |i|
idxar.combination(i).each do |x|
x = [0] + x + [n]
ans << x.each_cons(2).map{|from, to| s.slice(from, (to - from))}.map{|arr| base10(arr)}.inject(:+)
end
end
puts ans.inject(:+)
end
# AC
s = gets.chomp
n = s.length
ans = 0
(1 << (n - 1)).times do |mask|
expr = []
(0...n).each do |i|
if (mask & (1 << i)).zero? then
expr += [s[i]]
else
expr += [s[i], "+"]
end
end
ans += eval(expr.join)
end
puts ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment