0
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?

paiza.ioでelixir その348

Last updated at Posted at 2025-11-18

概要

paiza.ioでelixirやってみた。
atcoder、見つけたので、やってみた。

参考にしたページ

練習問題

ABC 088 B - Card Game for Two
N枚のカードを二人で交互に取っていき、カードに書かれている数字の和の差を求める問題。

投入するソース

2
3 1

期待値

2

サンプルコード

defmodule Main do
	def main do
		n = IO.gets("") 
		    |> String.trim() 
		    |> String.to_integer
		a = IO.gets("") 
		    |> String.trim() 
		    |> String.split(" ", trim: true) 
		    |> Enum.map(&String.to_integer(&1))
		    |> Enum.sort 
		    |> Enum.reverse
		total = a 
		    |> Enum.sum
		alice = a 
		    |> Enum.take_every(2) 
		    |> Enum.sum
		bob = total - alice
		IO.puts(alice - bob)
	end
end

実行結果

2

成果物

以上。

0
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
0
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?