国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

《Lua程序設(shè)計(jì)第四版》 第二部分9~13章自做練習(xí)題答案

這篇具有很好參考價(jià)值的文章主要介紹了《Lua程序設(shè)計(jì)第四版》 第二部分9~13章自做練習(xí)題答案。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

Lua程序設(shè)計(jì)第四版第二部分編程實(shí)操自做練習(xí)題答案,帶?為重點(diǎn)。

9.1

請(qǐng)編寫一個(gè)函數(shù)integral,該函數(shù)以一個(gè)函數(shù)f為參數(shù)并返回其積分的近似值

使用右矩陣法近似積分值

function integral(f)
    return function(a, b)
        local sum = 0
        for i = 1, 10000, 1 do
            sum = sum + f(a + (b - a) * i / 10000)
        end
        return sum * (b - a) / 10000
    end
end

function x3(x)
    return 2 * x + 3 * x ^ 3
end

jf = integral(x3)
print(jf(0, 10)) -- 7601.510075 近似 7600

9.2

如下代碼段將輸出什么結(jié)果

function F(x)
    return {
        set = function(y)
            x = y
        end,
        get = function()
            return x
        end
    }
end

o1 = F(10)
o2 = F(20)
print(o1.get(), o2.get())
o2.set(100)
o1.set(300)
print(o1.get(), o2.get())
-- 10      20
-- 300     100

9.3 ?

編寫練習(xí)5.4的柯里化版本

柯里化(Currying)是把接受多個(gè)參數(shù)的函數(shù)變換成接受一個(gè)單一參數(shù)(最初函數(shù)的第一個(gè)參數(shù))的函數(shù),并且返回接受余下的參數(shù)且返回結(jié)果的新函數(shù)的技術(shù)。

function newpoly(t)
    return function(x)
        local sum = 0
        for i, v in ipairs(t) do
            sum = sum + v * x ^ (i - 1)
        end
        return sum
    end
end

t = newpoly({3, 0, 1})
print(t(0))
print(t(5))
print(t(10))

9.4

使用幾何區(qū)域系統(tǒng)的例子,繪制一個(gè)北半球所能看到的峨眉月

編寫一個(gè)被其他函數(shù)B包含的函數(shù)A時(shí),被包含的函數(shù)A可以訪問(wèn)包含其的函數(shù)B的所有局部變量,這種特性被稱為詞法定界

-- 利用高階函數(shù)和詞法定界,定義一個(gè)指定圓心和半徑創(chuàng)建圓盤的工廠 --
function disk(cx, cy, r)
    return function(x, y)
        return (x - cx) ^ 2 + (y - cy) ^ 2 <= r ^ 2
    end
end

-- 創(chuàng)建一個(gè)指定邊界的軸對(duì)稱圖形
function rect(left, right, top, bottom)
    return function(x, y)
        return left <= x and x <= right and bottom <= y and y <= top
    end
end

-- 創(chuàng)建任何區(qū)域的補(bǔ)集
function complement(r)
    return function(x, y)
        return not r(x, y)
    end
end

-- 創(chuàng)建任何區(qū)域的并集
function union(r1, r2)
    return function(x, y)
        return r1(x, y) or r2(x, y)
    end
end

-- 交集
function intersection(r1, r2)
    return function(x, y)
        return r1(x, y) and r2(x, y)
    end
end

-- 差集
function difference(r1, r2)
    return function(x, y)
        return r1(x, y) and not r2(x, y)
    end
end

-- 按指定增量平移區(qū)域
function translate(r, dx, dy)
    return function(x, y)
        return r(x - dx, y - dy)
    end
end

function plot(r, M, N, file)
    f = io.open(file, "w")
    f:write("P1\n", M, " ", N, "\n")
    for i = 1, N, 1 do
        local y = (N - i * 2) / N
        for j = 1, M do
            local x = (j * 2 - M) / M
            f:write(r(x, y) and "1" or "0")
        end
        f:write("\n")
    end
    f:close()
end

circle = disk(0, 0, 0.5)
circle2 = translate(circle, -0.3, 0.2)
shape = difference(circle, circle2)
plot(shape, 512, 512, "test.pbm")

9.5 ?

在幾何區(qū)域系統(tǒng)的例子中,添加一個(gè)函數(shù)來(lái)實(shí)現(xiàn)將指定的區(qū)域旋轉(zhuǎn)指定的角度

-- 創(chuàng)建一個(gè)指定邊界的軸對(duì)稱圖形
function rect(left, right, top, bottom)
    return function(x, y)
        return left <= x and x <= right and bottom <= y and y <= top
    end
end

-- 創(chuàng)建任何區(qū)域的并集
function union(r1, r2)
    return function(x, y)
        return r1(x, y) or r2(x, y)
    end
end

-- 圖形根據(jù)坐標(biāo)軸原點(diǎn)順時(shí)針旋轉(zhuǎn)d弧度
function rotate(r, d)
    return function(x, y)
        return r(-math.cos(d) * x + y * math.sin(d), -math.sin(d) * x - math.cos(d) * y)
    end
end

function plot(r, M, N, file)
    f = io.open(file, "w")
    f:write("P1\n", M, " ", N, "\n")
    for i = 1, N, 1 do
        local y = (N - i * 2) / N
        for j = 1, M do
            local x = (j * 2 - M) / M
            f:write(r(x, y) and "1" or "0")
        end
        f:write("\n")
    end
    f:close()
end

shape1 = rect(-0.5, 0.5, 0.5, -0.5)
shape2 = rect(-0.25, 0.25, 0.75, -0.25)
shape1 = rotate(shape, math.pi * 0.1) -- s1所處的坐標(biāo)系平面被旋轉(zhuǎn)了,s2的并沒(méi)有
shape = union(shape1, shape2)
plot(shape, 512, 512, "test.pbm")

10.1

請(qǐng)編寫一個(gè)函數(shù)split,該函數(shù)接收兩個(gè)參數(shù),第1個(gè)參數(shù)是字符串,第2個(gè)參數(shù)是分隔符模式,函數(shù)的返回值是分隔符分割后的原始字符串中每一部分的序列

function split(s, sep)
    t = {}
    -- tmpindex = 0
    -- index = 1
    -- index = string.find(s, sep, index, true)
    -- while index do
    --     table.insert(t, string.sub(s, tmpindex + 1, index))
    --     tmpindex = index
    --     index = string.find(s, sep, index + 1, true)
    -- end
    -- if index ~= #s then
    --     table.insert(t, string.sub(s, tmpindex + 1, #s))
    -- end
    for w in string.gmatch(s, "[^" .. sep .. "]+") do
        t[#t + 1] = w
    end
    return t
end

t = split("a whole new world", " ")
-- t = split("", " ")
for k, v in pairs(t) do
    print(k, v)
end

10.2 ?

模式 [^%d%u] 與 [%D%U] 是否等價(jià)

不一樣

[^%d%u] 是 (數(shù)字∪大寫字母)的補(bǔ)集 = 排除數(shù)字和大寫字母
> string.find("123ABCA","[^%d%u]") 
nil
> string.find("123ABCa","[^%d%u]") 
7       7
[%D%U] 是  數(shù)字的補(bǔ)集∪大寫字母的補(bǔ)集 = 全集
> string.find("123ABC","[%D%U]")
1       1
使用第一種是正確的

10.3

請(qǐng)編寫一個(gè)函數(shù)transliterate,該函數(shù)接收兩個(gè)參數(shù),第1個(gè)參數(shù)是字符串,第2個(gè)參數(shù)是一個(gè)表。函數(shù)transliterate根據(jù)第2個(gè)參數(shù)中的表使用一個(gè)字符替換字符串中的字符。如果表中將a映射為b,那么該函數(shù)則將所有a替換為b。如果表中將a映射為false,那么該函數(shù)則把結(jié)果中的所有a移除

function transliterate(s, t)
    return string.gsub(s, ".", function(w)
        if t[w] == false then
            return ""
        else
            return t[w]
        end
    end)
end

s = "apple"
s = transliterate(s, {
    a = "b",
    p = false,
    l = "i",
    e = "g"
})
print(s)

10.4 ?

我們定義了一個(gè)trim函數(shù)。

  • 構(gòu)造一個(gè)可能會(huì)導(dǎo)致trim耗費(fèi)O(n^2)時(shí)間復(fù)雜度的字符串
  • 重寫這個(gè)函數(shù)使得其時(shí)間復(fù)雜度為O(n)
function trim1(s)
    return string.gsub(s, "^%s*(.-)%s*$", "%1")
end

-- "雙指針?lè)▽?shí)現(xiàn)"
function trim2(s)
    local top = string.find(s, "%S")
    local tail = #s
    for i = 1, #s, 1 do
        if string.find(string.sub(s, -i, -i), "%s") then
            tail = #s - i
        else
            break
        end
    end
    return string.sub(s, top, tail)
end

s = string.rep(" ", 2 ^ 13)

s = (" " .. "a" .. s .. "a" .. " ")

start = os.clock()
t = trim2(s)
print(t:len() == 2 ^ 13 + 2)
print(os.clock() - start)

10.5

請(qǐng)使用轉(zhuǎn)義序列\(zhòng)x編寫一個(gè)函數(shù),將一個(gè)二進(jìn)制字符串格式化為L(zhǎng)ua語(yǔ)言中的字符串常量

-- 二進(jìn)制字符串格式化為L(zhǎng)ua語(yǔ)言中的字符串常量
function escape(s)
    local pattern = string.rep("[01]", 8)
    s = string.gsub(s, pattern, function(bits)
        return string.format("\\x%02X", tonumber(bits, 2))
    end)
    return s
end

print(escape( "0100100001100001011100000111000001111001001000000110010101110110011001010111001001111001011001000110000101111001"))
-- \x48\x61\x70\x70\x79\x20\x65\x76\x65\x72\x79\x64\x61\x79

10.6

請(qǐng)為UTF-8字符串重寫10.3

function transliterate(s, t)
    return string.gsub(s, utf8.charpattern, function(w)
        if t[w] == false then
            return ""
        else
            return t[w]
        end
    end)
end

s = "天氣真好"
s = transliterate(s, {
    ["天"] = "大",
    ["氣"] = false,
    ["真"] = "爺"
})
print(s)

10.7

請(qǐng)編寫一個(gè)函數(shù),該函數(shù)用于逆轉(zhuǎn)一個(gè)UTF-8字符串

function reverseUTF8(s)
    t = {}
    for w in string.gmatch(s, utf8.charpattern) do
        table.insert(t, 1, w)
    end
    return table.concat(t)
end

print(reverseUTF8("天氣真好"))

ANTI SPIDER BOT -- www.cnblogs.com/linxiaoxu

11.1

請(qǐng)改寫該程序,使它忽略長(zhǎng)度小于4個(gè)字母的單詞

local counter = {}

io.input(arg[2] or "test.txt")

for line in io.lines() do
    -- 不能放在這,相當(dāng)于無(wú)限執(zhí)行g(shù)match死循環(huán),gmatch只執(zhí)行一次獲取迭代器
    for word in string.gmatch(line, "%w+") do
        if #word < 4 then
            goto a
        end
        counter[word] = (counter[word] or 0) + 1
        ::a:: -- 跳過(guò)當(dāng)前計(jì)數(shù)
    end
end

local words = {}
for k, _ in pairs(counter) do
    words[#words + 1] = k
end

table.sort(words, function(w1, w2)
    return counter[w1] > counter[w2] or counter[w1] == counter[w2] and w1 < w2
end)

local n = math.min(tonumber(arg[1]) or math.huge, #words)

for i = 1, n, 1 do
    print(i, words[i], counter[words[i]])
end

11.2 ?

該程序還能從一個(gè)文本文件中讀取要忽略的單詞列表

local counter = {}
local ignore = {}

io.input(arg[2] or "test.txt")
f = io.open(arg[3] or "ignore.txt", 'r')
for line in f:lines() do
    ignore[string.match(line, "%w+")] = true
end

for line in io.lines() do
    -- 不能放在這,相當(dāng)于無(wú)限執(zhí)行g(shù)match死循環(huán),gmatch只執(zhí)行一次獲取迭代器
    for word in string.gmatch(line, "%w+") do
        if #word < 4 or ignore[word] then
            goto a
        end
        counter[word] = (counter[word] or 0) + 1
        ::a:: -- 跳過(guò)當(dāng)前計(jì)數(shù)
    end
end

local words = {}
for k, _ in pairs(counter) do
    words[#words + 1] = k
end

table.sort(words, function(w1, w2)
    return counter[w1] > counter[w2] or counter[w1] == counter[w2] and w1 < w2
end)

local n = math.min(tonumber(arg[1]) or math.huge, #words)

for i = 1, n, 1 do
    print(i, words[i], counter[words[i]])
end

12.1

該函數(shù)返回指定日期和時(shí)間后恰好一個(gè)月的日期和時(shí)間(按數(shù)字形式表示)

function oneMonthLater(t)
    t.month = t.month + 1
    return os.time(t)
end

print(oneMonthLater(os.date("*t")))

12.2

該函數(shù)返回指定日期是星期幾(用整數(shù)表示,1表示星期天

function wday(t)
    return t.wday
end

print(wday(os.date("*t")))

12.3

該函數(shù)的參數(shù)為一個(gè)日期和時(shí)間(數(shù)值),返回當(dāng)天中已經(jīng)經(jīng)過(guò)的秒數(shù)

function todayPassSeconds(t)
    t = os.date("*t", t)
    return t.hour * 3600 + t.min * 60 + t.sec
end

print(todayPassSeconds(os.time()))

12.4

該函數(shù)的參數(shù)為年,返回該年中第一個(gè)星期五是第幾天

function findFirstFriday(y)
    t = os.date("*t")
    t.year = y
    t.month = 1
    for i = 1, 7, 1 do
        t.day = i
        t = os.date("*t", os.time(t))
        if t.yday == 6 then
            return t.yday
        end
    end
end

print(findFirstFriday(2023))

12.5

該函數(shù)用于計(jì)算兩個(gè)指定日期之間相差的天數(shù)

function timeDiffDays(x, y)
    seconds = os.time(x) - os.time(y)
    return seconds // (24 * 3600)
end

t = os.date("*t")
t.year = 2012
print(timeDiffDays(os.date("*t"), t))

12.6

該函數(shù)用于計(jì)算兩個(gè)指定日期之間相差的月份

function timeDiffMonth(x, y)
    year = x.year - y.year
    month = x.month - y.month
    return math.abs(year) * 12 + math.abs(month)
end

t = os.date("*t")
t.year = 2023
t.month = 7
print(timeDiffMonth(os.date("*t"), t))

12.7

向指定日期添加一個(gè)月再添加一天得到的結(jié)果,是否與先添加一天再添加一個(gè)月得到的結(jié)果相同

buff = {
    year = 2023,
    month = 6,
    day = 30
}

t = os.date("*t", os.time(buff))
t.day = t.day + 1
t.month = t.month + 1

t2 = os.date("*t", os.time(buff))
t2.month = t2.month + 1
t2.day = t2.day + 1

print(os.difftime(os.time(t), os.time(t2)))

t = os.date("*t", os.time(buff))
t.day = t.day + 1
t = os.date("*t", os.time(t))
t.month = t.month + 1

t2 = os.date("*t", os.time(buff))
t2.month = t2.month + 1
t2 = os.date("*t", os.time(t2))
t2.day = t2.day + 1

print(os.difftime(os.time(t), os.time(t2)))

[[
0.0
86400.0 第二種方法會(huì)產(chǎn)生不同結(jié)果
]]

12.8

該函數(shù)用于輸出操作系統(tǒng)的時(shí)區(qū)

時(shí)區(qū)劃分是規(guī)定將全球劃分為24個(gè)時(shí)區(qū),東、西各12個(gè)時(shí)區(qū)。1884年在華盛頓召開(kāi)的一次國(guó)際經(jīng)度會(huì)議(又稱國(guó)際子午線會(huì)議)上,規(guī)定將全球劃分為24個(gè)時(shí)區(qū)(東、西各12個(gè)時(shí)區(qū))。規(guī)定英國(guó)(格林尼治天文臺(tái)舊址)為中時(shí)區(qū)(零時(shí)區(qū))、東112區(qū),西112區(qū)。每個(gè)時(shí)區(qū)橫跨經(jīng)度15度,時(shí)間正好是1小時(shí)。最后的東、西第12區(qū)各跨經(jīng)度7.5度,以東、西經(jīng)180度為界。

function timeZone()
    local now = os.time()
    local glnz = os.time(os.date("!*t")) -- 格林尼治時(shí)間
    return (now - glnz) // 3600
end

print(timeZone())
-- 8 東8區(qū)

13.1 ?

該函數(shù)用于進(jìn)行無(wú)符號(hào)整型數(shù)的取模運(yùn)算

將無(wú)符號(hào)整數(shù)最低位提取充當(dāng)b(0或1),其余部分為a,a必為偶數(shù)。a再拆分為 2 * a/2,2為j,a/2為k。

\[(a+b) \mod c = ((a \mod c) + (b \mod c)) \mod c \\ (j*k) \mod c = ((j \mod c) * (k \mod c)) \mod c \]
--設(shè)條件 d<= 2^64 -1 , c <= 2^63-1
function unsignedMod(d, c)
    local even = d & -2
    local odd = d & 1
    local res1 = ((2 % c) * ((even >> 1) % c)) % c -- 等價(jià)于 even % c
    local res2 = (res1 + (odd % c)) % c
    return res2
end

print(unsignedMod(-101, 4294967296) == 4294967195)
print(unsignedMod(-1, math.maxinteger) == 1)
print(unsignedMod(-1111111, 114514) == 59155)

13.2

實(shí)現(xiàn)計(jì)算Lua語(yǔ)言中整型數(shù)所占位數(shù)的不同方法

-- 忽略符號(hào)位,計(jì)算剩下的63位中共占用幾位
function countBits1(d)
    local count = 0
    while d ~= 0 do
        d = d // 2
        count = count + 1
    end
    return count
end

function countBits2(d)
    local count = 0
    d = d & math.maxinteger
    while d ~= 0 do
        d = d >> 1
        count = count + 1
    end
    return count
end

print(countBits1(math.maxinteger) == 63)
print(countBits1(10) == 4)
print(countBits1(1) == 1)
print(countBits1(0) == 0)

print(countBits2(math.maxinteger) == 63)
print(countBits2(10) == 4)
print(countBits2(1) == 1)
print(countBits2(0) == 0)

13.3

如何判斷一個(gè)指定整數(shù)是不是2的整數(shù)次冪

-- 忽略符號(hào)位,計(jì)算剩下的63位中共占用幾位
function isPowerOf2(d)
    if d <= 0 then
        return false
    end
    while d & 1 == 0 do
        d = d >> 1
    end
    d = d >> 1
    if d > 0 then
        return false
    else
        return true
    end
end

print(isPowerOf2(1))
print(isPowerOf2(2))
print(isPowerOf2(3))
print(isPowerOf2(4))
print(isPowerOf2(5))
print(isPowerOf2(6))
print(isPowerOf2(7))
print(isPowerOf2(8))

13.4

該函數(shù)用于計(jì)算指定整數(shù)的漢明權(quán)重(數(shù)二進(jìn)制表示的1的個(gè)數(shù))

function hw(d)
    local count = 0
    while d ~= 0 do
        if d & 1 == 1 then
            count = count + 1
        end
        d = d >> 1
    end
    return count
end

print(hw(1)) -- 1
print(hw(2)) -- 1
print(hw(3)) -- 2
print(hw(4)) -- 1
print(hw(5)) -- 2
print(hw(6)) -- 2
print(hw(7)) -- 3
print(hw(8)) -- 1

print(hw(-1)) -- FFFF  64
print(hw(-2)) -- FFFE  63
print(hw(-3))
print(hw(-4))
print(hw(-5))
print(hw(-6))
print(hw(-7))
print(hw(-8))

13.5

該函數(shù)用于判斷注定整數(shù)的二進(jìn)制表示是否為回文數(shù)

function isPalindrome(d)
    local t = {}
    while d ~= 0 do
        table.insert(t, d & 1)
        d = d >> 1
    end
    for i = 1, 32, 1 do
        if t[i] ~= t[64 - i + 1] then
            return false
        end
    end
    return true
end

print(isPalindrome(1))
print(isPalindrome(0))
print(isPalindrome(-1))
print(isPalindrome(math.mininteger + 1))

13.6 ?

請(qǐng)?jiān)贚ua語(yǔ)言實(shí)現(xiàn)一個(gè)比特?cái)?shù)組

  • newBiteArrary(n) 創(chuàng)建一個(gè)具有n個(gè)比特的數(shù)組
  • setBit(a, n, v) 將布爾值v賦值給數(shù)組a的第n位
  • testBit(a, n) 將第n位的值作為布爾值返回
function newBiteArrary(n)
    local t = {}
    local count = (n - 1) // 64 + 1
    for i = 1, n, 1 do
        table.insert(t, 0)
    end
    return t
end

function setBit(a, n, v)
    local count = (n - 1) // 64 + 1
    local n = (n - 1) % 64 + 1
    local tmp1 = math.mininteger >> (n - 1) -- 000001000000
    local tmp2 = ~tmp1 -- 1111101111111
    if v then
        a[count] = a[count] | tmp1
    else
        a[count] = a[count] & tmp2
    end
end

function testBit(a, n)
    local count = (n - 1) // 64 + 1
    local n = (n - 1) % 64 + 1
    local tmp1 = math.mininteger >> (n - 1) -- 000001000000
    if tmp1 & a[count] == 0 then
        return false
    else
        return true
    end
end

a = newBiteArrary(300)
setBit(a, 1, true)
setBit(a, 100, true)
setBit(a, 105, true)
setBit(a, 105, false)
setBit(a, 300, true)
print(testBit(a, 1))
print(testBit(a, 100))
print(testBit(a, 105))
print(testBit(a, 300))

13.7 ?

假設(shè)有一個(gè)以一系列記錄組成的二進(jìn)制文件,其中的每一個(gè)記錄的格式為

struct Record{
 int x;
 char[3] code;
 float value;
};

請(qǐng)編寫一個(gè)程序,該程序讀取這個(gè)文件,然后輸出value字段的總和文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-647993.html

function saveRecords(t)
    local f = io.open("records.txt", "w")
    for _, v in ipairs(t) do
        f:write(string.pack("j", v.x))
        f:write(string.pack("z", v.code))
        f:write(string.pack("n", v.value))
    end
    f:close()
end

function readCalcuteValue()
    local f = io.open("records.txt", "rb")
    local s = f:read('a')
    f:close()
    local i = 1
    local total = 0
    while i <= #s do
        local x, code, value
        x, i = string.unpack('j', s, i)
        code, i = string.unpack('z', s, i)
        value, i = string.unpack('n', s, i)
        print(x, code, value)
        total = total + value
    end
    return total
end

t = {{
    x = 100000,
    code = "abc",
    value = 100
}, {
    x = 200000,
    code = "def",
    value = 200
}, {
    x = 300000,
    code = "ghi",
    value = 300
}, {
    x = 400000,
    code = "jkl",
    value = 400
}}

saveRecords(t)
sum = readCalcuteValue()
print(sum)
[[
100000  abc     100.0
200000  def     200.0
300000  ghi     300.0
400000  jkl     400.0
1000.0
]]

到了這里,關(guān)于《Lua程序設(shè)計(jì)第四版》 第二部分9~13章自做練習(xí)題答案的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 《Lua程序設(shè)計(jì)》--學(xué)習(xí)2

    《Lua程序設(shè)計(jì)》--學(xué)習(xí)2

    Lua語(yǔ)言中的 表 本質(zhì)上是一種 輔助數(shù)組 (associative array),這種數(shù)組不僅可以使用數(shù)值作為索引,也可以使用字符串或其他任意類型的值作為索引(nil除外)。 當(dāng)調(diào)用函數(shù)math.sin時(shí),我們可能認(rèn)為是“調(diào)用了math庫(kù)中函數(shù)sin”;而對(duì)于Lua語(yǔ)言來(lái)說(shuō),其實(shí)際含義是“以字符串\\\"s

    2024年02月08日
    瀏覽(16)
  • 《Lua程序設(shè)計(jì)》--學(xué)習(xí)4

    《Lua程序設(shè)計(jì)》--學(xué)習(xí)4

    在Lua語(yǔ)言中,函數(shù)是嚴(yán)格遵循詞法定界(lexicalscoping)的 第一類值 (first-classvalue)。 “第一類值”意味著Lua語(yǔ)言中的函數(shù)與其他常見(jiàn)類型的值(例如數(shù)值和字符串)具有同等權(quán)限:一個(gè)程序可以將某個(gè)函數(shù)保存到變量中(全局變量和局部變量均可)或表中,也可以將某個(gè)函

    2024年02月08日
    瀏覽(16)
  • 《Lua程序設(shè)計(jì)》--學(xué)習(xí)3

    《Lua程序設(shè)計(jì)》--學(xué)習(xí)3

    Lua 文件 I/O | 菜鳥(niǎo)教程 (runoob.com) 對(duì)于文件操作來(lái)說(shuō),I/O庫(kù)提供了兩種不同的模型 。簡(jiǎn)單模型虛擬了一個(gè)當(dāng)前輸入流(current input stream)和一個(gè)當(dāng)前輸出流(current output stream),其I/O操作是通過(guò)這些流實(shí)現(xiàn)的。I/O庫(kù)把當(dāng)前輸入流初始化為進(jìn)程的標(biāo)準(zhǔn)輸入(C語(yǔ)言中的stdin),將當(dāng)

    2024年02月08日
    瀏覽(18)
  • Java Web程序設(shè)計(jì)課后習(xí)題答案 第四章

    第4章 一、填空 1.如果當(dāng)前Web資源不想處理請(qǐng)求, RequestDispatcher接口提供了一個(gè) forward()方法,該方法可以將當(dāng)前請(qǐng)求傳遞給其他Web資源對(duì)這些信息進(jìn)行處理并響應(yīng)給客戶端,這種方式稱為請(qǐng)求轉(zhuǎn)發(fā)。 2.Servlet API中,專門用來(lái)封裝HTTP響應(yīng)消息的接口是HttpServletResponse。 3. 重定向指

    2024年04月23日
    瀏覽(94)
  • 《匯編語(yǔ)言》王爽(第四版) 課程設(shè)計(jì)1

    《匯編語(yǔ)言》王爽(第四版) 課程設(shè)計(jì)1

    文章目錄 前言 一、課程設(shè)計(jì)任務(wù) 二、任務(wù)分析 1.公司數(shù)據(jù)的格式 2.數(shù)據(jù)轉(zhuǎn)為字符串 3.顯示多個(gè)數(shù)據(jù) 三、實(shí)現(xiàn)代碼 總結(jié) 本文是王爽老師《匯編語(yǔ)言》(第四版) 課程設(shè)計(jì)1 “將實(shí)驗(yàn)七中給定的公司數(shù)據(jù)顯示在屏幕上”的分析及代碼。這是目前寫的最綜合的程序,要用到實(shí)驗(yàn)七

    2024年02月13日
    瀏覽(17)
  • 軟考13-上午題-程序設(shè)計(jì)語(yǔ)言概述

    軟考13-上午題-程序設(shè)計(jì)語(yǔ)言概述

    1-1、低級(jí)語(yǔ)言 機(jī)器語(yǔ)言(由0,1組成) 匯編語(yǔ)言(ADD-加法;SUB-減法)——面向機(jī)器的語(yǔ)言 計(jì)算機(jī)只能理解0、1構(gòu)成的機(jī)器語(yǔ)言 ? 1-2、高級(jí)語(yǔ)言 java C C++ PHP Phthon ...... 與自然語(yǔ)言接近,更抽象。 目的:高級(jí)程序設(shè)計(jì)語(yǔ)言(匯編語(yǔ)言、高級(jí)語(yǔ)言)—【翻譯】—機(jī)器語(yǔ)言 翻譯的方

    2024年01月22日
    瀏覽(25)
  • 微信小程序畢業(yè)設(shè)計(jì)作品成品(13)微信小程序校園澡堂浴室預(yù)約系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)

    微信小程序畢業(yè)設(shè)計(jì)作品成品(13)微信小程序校園澡堂浴室預(yù)約系統(tǒng)設(shè)計(jì)與實(shí)現(xiàn)

    博主介紹: 《Vue.js入門與商城開(kāi)發(fā)實(shí)戰(zhàn)》《微信小程序商城開(kāi)發(fā)》圖書作者,CSDN博客專家,在線教育專家,CSDN鉆石講師;專注大學(xué)生畢業(yè)設(shè)計(jì)教育和輔導(dǎo)。 所有項(xiàng)目都配有從入門到精通的基礎(chǔ)知識(shí)視頻課程,免費(fèi) 項(xiàng)目配有對(duì)應(yīng)開(kāi)發(fā)文檔、開(kāi)題報(bào)告、任務(wù)書、PPT、論文模版

    2024年02月07日
    瀏覽(28)
  • 讀程序員的README筆記13_技術(shù)設(shè)計(jì)流程(上)

    讀程序員的README筆記13_技術(shù)設(shè)計(jì)流程(上)

    3.4.1.1.?外界干擾是深度工作的“殺手” 3.4.1.2.?避免所有的交流方式 3.4.1.2.1.?關(guān)閉聊天 3.4.1.2.2.?關(guān)閉電子郵件 3.4.1.2.3.?禁用電話通知 3.4.1.2.4.?換個(gè)地方坐 3.4.2.1.?有形產(chǎn)出是一份設(shè)計(jì)文檔 4.2.3.1.?如果有一個(gè)以上的問(wèn)題,詢問(wèn)哪些問(wèn)題是最優(yōu)先的 4.3.7.1.?注意與外人交流時(shí)不

    2024年02月04日
    瀏覽(53)
  • 《Verilog數(shù)字系統(tǒng)設(shè)計(jì)教程》夏宇聞 第四版思考題答案(第5章)

    《Verilog數(shù)字系統(tǒng)設(shè)計(jì)教程》夏宇聞 第四版思考題答案(第5章)

    1.為什么建議在編寫Verilog模塊程序時(shí),如果用到 if 語(yǔ)句建議大家把配套的else情況也考慮在內(nèi)? ??因?yàn)槿绻麤](méi)有配套的else語(yǔ)句,在不滿足if條件語(yǔ)句時(shí),將會(huì)保持原來(lái)的狀態(tài)不變,從而在綜合時(shí)會(huì)產(chǎn)生一個(gè)鎖存器,而這是設(shè)計(jì)不想要的結(jié)果。 2.用 if(條件1) 語(yǔ)句;elseif (條件

    2024年02月08日
    瀏覽(58)
  • 基于微信評(píng)選投票小程序畢業(yè)設(shè)計(jì)作品成品(13)參賽列表和參賽排名接口

    博主介紹: 《Vue.js入門與商城開(kāi)發(fā)實(shí)戰(zhàn)》《微信小程序商城開(kāi)發(fā)》圖書作者,CSDN博客專家,在線教育專家,CSDN鉆石講師;專注大學(xué)生畢業(yè)設(shè)計(jì)教育和輔導(dǎo)。 所有項(xiàng)目都配有從入門到精通的基礎(chǔ)知識(shí)視頻課程,免費(fèi) 項(xiàng)目配有對(duì)應(yīng)開(kāi)發(fā)文檔、開(kāi)題報(bào)告、任務(wù)書、PPT、論文模版

    2024年02月07日
    瀏覽(18)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包