Lua > 洛谷
- P1000 超級瑪麗游戲
- P1001 A+B Problem
- P1008 [NOIP 1998 普及組] 三連擊
- P1035 [NOIP 2002 普及組] 級數求和
- P1046 [NOIP 2005 普及組] 陶陶摘蘋果
- P1047 [NOIP 2005 普及組] 校門外的樹
- P1085 [NOIP 2004 普及組] 不高興的津津
- P1089 [NOIP 2004 提高組] 津津的儲蓄計劃
- P1150 Peter 的煙
- P1151 子數整數
P1000 超級瑪麗游戲
https://www.luogu.com.cn/problem/P1000#ide
print([[ ********************####....#.#..###.....##....###.......###### ### ###........... #...# #...###*####### #.#.# #.#.#####*******###### #.#.# #.#.#...#***.****.*###.... #...# #...#....**********##..... ### ###....**** *****....#### ########## ######
##############################################################
#...#......#.##...#......#.##...#......#.##------------------#
###########################################------------------#
#..#....#....##..#....#....##..#....#....#####################
########################################## #----------#
#.....#......##.....#......##.....#......# #----------#
########################################## #----------#
#.#..#....#..##.#..#....#..##.#..#....#..# #----------#
########################################## ############]])
P1001 A+B Problem
https://www.luogu.com.cn/problem/P1001#ide
a = io.read('*n')
b = io.read('*n')
print(a + b)
P1008 [NOIP 1998 普及組] 三連擊
https://www.luogu.com.cn/problem/P1008#ide
function printTable(myTable)for key, value in pairs(myTable) doprint(key, value)end
endfunction getDigits(num)while num > 0 don = num % 10if n == 0 or st[n] thenst = {}returnendst[n] = truenum = math.floor(num / 10)end-- printTable(st)
endfunction isDifer(first, second, third)st = {}getDigits(first)-- printTable(st)-- print('----')getDigits(second)-- printTable(st)-- print('----')getDigits(third)-- printTable(st)count = 0for _ in pairs(st) do count = count + 1 end-- print(count, '----------')return count == 9
endfunction main()for i = 1, 9 dofor j = 1, 9 dorepeatif j == i thenbreakendfor k = 1, 9 dorepeatif k == i or k == j thenbreakendfirst = i*100 +j*10 + ksecond, third = first * 2, first * 3if isDifer(first, second, third) thenprint(first .. ' ' .. second .. ' ' .. third)enduntil trueenduntil trueendend
endmain()
P1035 [NOIP 2002 普及組] 級數求和
https://www.luogu.com.cn/problem/P1035#ide
k = io.read("*n")
i = 1
s = 0
while s <= k dos = s + 1/ii = i + 1
end
print(i-1)
P1046 [NOIP 2005 普及組] 陶陶摘蘋果
https://www.luogu.com.cn/problem/P1046#ide
-- 讀取第一行
local line1 = io.read("*l")
local hs = {}
for num in line1:gmatch("%S+") dotable.insert(hs, tonumber(num))
end
-- for k, v in pairs(hs) do
-- print(k, v)
-- end-- 讀取第二行
local line2 = io.read("*l")
for num in line2:gmatch("%S+") domh = tonumber(num)-- print(mh)break
endmh = mh + 30
cnt = 0
for i = 1, 10 do-- print(mh, hs[i])if mh >= hs[i] thencnt = cnt + 1end
end
print(cnt)
P1047 [NOIP 2005 普及組] 校門外的樹
https://www.luogu.com.cn/problem/P1047#ide
line1 = io.read("*l")
-- print(line1)
lm = {}
for num in line1:gmatch("%S+") dotable.insert(lm, tonumber(num))
end-- for k, v in pairs(lm) do
-- print(k, v)
-- endflags = {}
for num = 0, lm[1] doflags[num] = true
end
-- for k, v in pairs(flags) do
-- print(k, v)
-- endfor i = 1, lm[2] doline = io.read("*l")uv = {}for num in line:gmatch("%S+") dotable.insert(uv, tonumber(num))endfor j = uv[1], uv[2] doflags[j] = falseend
endcnt = 0
for k, v in pairs(flags) doif v thencnt = cnt + 1end
end
print(cnt)
P1085 [NOIP 2004 普及組] 不高興的津津
https://www.luogu.com.cn/problem/P1085#ide
ma = 8
mai = 0for i = 1, 7 dots = {}for num in io.read("*l"):gmatch("%S+") dotable.insert(ts, tonumber(num))endcur = ts[1] + ts[2]if cur > ma thenma, mai = cur, iend
end
print(mai)
P1089 [NOIP 2004 提高組] 津津的儲蓄計劃
https://www.luogu.com.cn/problem/P1089#ide
sum = 0
bal = 0
for i = 1, 12 dosum = sum + 300cur = io.read("*n")sum = sum - curif sum < 0 thenprint(-i)os.exit()endbal = bal + math.floor(sum/100)*100sum = sum - math.floor(sum/100)*100
end
print(sum + bal*1.2)
P1150 Peter 的煙
https://www.luogu.com.cn/problem/P1150#ide
nk = {}
for num in io.read("*l"):gmatch("%S+") dotable.insert(nk, tonumber(num))
endn, k = nk[1], nk[2]
r = n
while n >= k dor = r + math.floor(n/k)n = math.floor(n/k) + (n - math.floor(n/k) * k)
end
print(r)
P1151 子數整數
https://www.luogu.com.cn/problem/P1151#ide
k = io.read("*n")
cnt = 0
for i = 10000, 30000 dof, s, t = math.floor(i/100), math.floor(i/10)-math.floor(math.floor(i/10)/1000)*1000, i - math.floor(i/1000)*1000-- print(f, s, t)if f == math.floor(f/k) * k and s == math.floor(s/k) * k and t == math.floor(t/k) * k thencnt = cnt + 1print(i)end
end
if cnt == 0 thenprint("No")
end