【Lua】ElJudge 002 Set Intersection

http://acm.mipt.ru/judge/problems.pl?problem=002


問兩個集合的交集是什麼?


根據數據範圍掃一下就行了。。。


代碼:

function rt()
    return io.stdin:read("*n")
end
function rtable()
    local ans={}
    repeat
        local a=rt()
        if ans[a]==nil then ans[a]=0
        elseif a~=-1 then ans[a]=ans[a]+1 end
    until a==-1
    return ans
end
local a=rtable()
local b=rtable()
find=false
for i=1,1e6 do
    if a[i]~=nil and b[i]~=nil then
        print (i)
        find=true
    end
end
if not find then
    print("empty")
end


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章