Skip to content

Instantly share code, notes, and snippets.

@takano32 takano32/a.rb
Last active Aug 22, 2018

Embed
What would you like to do?
AtCoder - practice 1
#!/usr/bin/env ruby
#
# AtCoder の環境では '--disable-gems'
def at_coder?
not defined? Gem
end
# AtCoder では MiniTest が消されている
unless at_coder?
require 'minitest'
require 'minitest/unit'
class TestExample < MiniTest::Test
end
end
class TestExample
def test(input, expect)
variables = parse input
output = solve(*variables)
assert_equal expect, output
end
def test_example01
input = <<~INPUT
1
2 3
test
INPUT
expect = <<~EXPECT
6 test
EXPECT
.chomp
test(input, expect)
end
def test_example02
input = <<~INPUT
72
128 256
myonmyon
INPUT
expect = <<~EXPECT
456 myonmyon
EXPECT
.chomp
test(input, expect)
end
end
def solve(a, b, c, s)
"#{a + b + c} #{s}"
end
def parse(input)
variables = []
index = 0
input.each_line do |line|
line = line.chomp
case index
when 0
a = line
variables << a.to_i
when 1
b, c = line.split(' ')
variables << b.to_i
variables << c.to_i
when 2
s = line
variables << s
else
raise
end
index += 1
end
variables
end
def main
input = ARGF.read
variables = parse(input)
puts solve(*variables)
end
if __FILE__ == $0
if at_coder?
main
else
MiniTest.autorun
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.