結果

問題 No.81 すべて足すだけの簡単なお仕事です。
ユーザー 👑 obakyanobakyan
提出日時 2020-04-26 13:45:46
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,535 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 5,336 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-29 22:52:51
合計ジャッジ時間 1,461 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local q = io.read("*n", "*l")
local ps, ms = {}, {}
for i = 1, 25 do
  ps[i] = 0
  ms[i] = 0
end
for iq = 1, q do
  local s = io.read()
  local t = nil
  if s:sub(1, 1) == "-" then
    t = ms
    s = s:sub(2, #s)
  else
    t = ps
  end
  if s:find("%.") then
    local s1, s2 = s:match("(%d+)%.(%d+)")
    for i = 1, #s2 do
      local v = s2:sub(i, i):byte() - 48
      t[i + 15] = t[i + 15] + v
    end
    for i = 1, #s1 do
      local v = s1:sub(i, i):byte() - 48
      t[15 - #s1 + i] = t[15 - #s1 + i] + v
    end
  else
    for i = 1, #s do
      local v = s:sub(i, i):byte() - 48
      t[15 - #s + i] = t[15 - #s + i] + v
    end
  end
end
for i = 25, 2, -1 do
  if 10 <= ps[i] then
    local up = mfl(ps[i] / 10)
    ps[i] = ps[i] % 10
    ps[i - 1] = ps[i - 1] + up
  end
  if 10 <= ms[i] then
    local up = mfl(ms[i] / 10)
    ms[i] = ms[i] % 10
    ms[i - 1] = ms[i - 1] + up
  end
end
local t1, t2 = nil, nil
local flag = true
for i = 1, 25 do
  if ms[i] < ps[i] then
    break
  elseif ps[i] < ms[i] then
    flag = false
    break
  end
end
if flag then
  t1, t2 = ps, ms
else
  t1, t2 = ms, ps
end
for i = 25, 2, -1 do
  t1[i] = t1[i] - t2[i]
  while t1[i] < 0 do
    t1[i] = t1[i] + 10
    t1[i - 1] = t1[i - 1] - 1
  end
end
if not flag then
  io.write("-")
end
local first_point = 15
for i = 1, 14 do
  if 0 < t1[i] then
    first_point = i break
  end
end
for i = first_point, 15 do
  io.write(t1[i])
end
io.write(".")
for i = 16, 25 do
  io.write(t1[i])
end
io.write("\n")
0