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?

More than 5 years have passed since last update.

ABC088B - Card Game for Two

Posted at

問題

https://atcoder.jp/contests/abs/tasks/abc088_b
スクリーンショット 2019-11-27 23.04.25.png

1回目

回答

N = gets.to_i
A = gets.split.map &:to_i
 
for i in 0..N-2 do
  for j in 0..N-2-i do
    if A[j] < A[j+1] 
      hoji = A[j]
      A[j] = A[j+1]
      A[j+1] = hoji
    end
  end
end
 
i = 0
aliceSum = 0
bobSum = 0
while i < N
  aliceSum += A[i]
  if i+1 < N
    bobSum += A[i+1]
  end
  i += 2
end
 
puts aliceSum - bobSum

結果

スクリーンショット 2019-11-27 23.06.57.png

2回目

回答

N = gets.to_i
A = gets.split.map(&:to_i).sort.reverse

result = 0

for i in 0..N-1
  if i % 2 == 0
    result += A[i]
  else
    result -= A[i]
  end
end

puts result

結果

スクリーンショット 2019-11-27 23.17.16.png

感想

sortあるんか〜〜〜〜〜い

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?