local input = tonumber(io.read('*a'))
local flag = nil
while (input ~= 0 and input ~= 6174) or not flag do
flag = true
local t = {} output = ""
local n1, n2
table.insert(t, math.floor(input/1000))
table.insert(t, math.floor(input/100) % 10)
table.insert(t, math.floor(input/10) % 10)
table.insert(t, input % 10)
table.sort(t, function(a, b) return a > b end)
output = table.concat(t)
n1 = t[1] * 1000 + t[2] * 100 + t[3] * 10 + t[4]
table.sort(t, function(a, b) return a < b end)
output = output .. " - " .. table.concat(t)
n2 = t[1] * 1000 + t[2] * 100 + t[3] * 10 + t[4]
input = n1 - n2
t = {}
table.insert(t, math.floor(input/1000))
table.insert(t, math.floor(input/100) % 10)
table.insert(t, math.floor(input/10) % 10)
table.insert(t, input % 10)
output = output .. " = " .. table.concat(t)
print(output)
end
用LUA(和C++)刷PAT (Advanced Level) ——1069 The Black Hole of Numbers
最新推荐文章于 2024-09-08 21:26:22 发布