1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

概要

paiza.ioでelixirやってみた。
atcoderやってみた。

参考にしたページ

問題

image.png

サンプルコード


defmodule Main do
	defp output({result, _, _, _}), do: result |> Enum.join(" ")
	defp division(_, {acc, rem, cs, as}) do
		quo = div(hd(rem), hd(as))
		rem1 = Enum.zip(rem, as) 
		|> Enum.map(fn {x, a} -> 
			x - a * quo 
		end)
		[c | cs1] = if Enum.empty?(cs), do: [nil], else: cs
		rem1 = (tl rem1) ++ [c]
		{[quo | acc], rem1, cs1, as}
	end
	defp solve(as, cs) do
		al = Enum.count(as)
		cl = Enum.count(cs)
		rem = Enum.take(cs, al)
		cs1 = Enum.drop(cs, al)
		1..cl - al + 1
		|> Enum.reduce({[], rem, cs1, as}, &division/2)
		|> output()
	end
	defp rev_integer_list(str) do
		str
		|> String.trim()
		|> String.split(" ")
		|> Enum.map(&String.to_integer/1)
		|> Enum.reverse()
	end
	def main do
		IO.read(:line)
		as = IO.read(:line) |> rev_integer_list()
		cs = IO.read(:line) |> rev_integer_list()
		solve(as, cs) 
		|> IO.puts()
	end
end
Main.main

成果物

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?