Powered by AppSignal & Oban Pro

PracticeA - Welcome to AtCoder

submit_3.livemd

PracticeA - Welcome to AtCoder

問題

回答3

defmodule Main do
  def main do
    :stdio
    |> IO.read(:all)
    |> solve()
    |> IO.puts()
  end

  defp split_lines(lines) do
    lines
    |> String.trim()
    |> String.split("\n")
  end

  defp split_words(words) do
    String.split(words, " ")
  end

  def solve(input) do
    [a, b, c, s] =
      input
      |> split_lines()
      |> Enum.map(&split_words/1)
      |> List.flatten()
      |> Enum.with_index()
      |> Enum.map(fn {word, index} ->
        case index do
          3 ->
            word

          _ ->
            String.to_integer(word)
        end
      end)

    "#{a + b + c} #{s}"
  end
end
"""
1
2 3
test
"""
|> Main.solve()
|> then(&(&1 == "6 test"))
"""
72
128 256
myonmyon
"""
|> Main.solve()
|> then(&(&1 == "456 myonmyon"))