-
-
Save takano32/ba3c8282c7944297306e67b102e3c05a to your computer and use it in GitHub Desktop.
AtCoder - practice 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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