結果
| 問題 |
No.81 すべて足すだけの簡単なお仕事です。
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2020-04-26 13:45:46 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,535 bytes |
| コンパイル時間 | 332 ms |
| コンパイル使用メモリ | 7,068 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-22 16:50:43 |
| 合計ジャッジ時間 | 1,178 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 |
ソースコード
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")