Notes - joyocaowei/joyocaowei.github.io GitHub Wiki

Linux Shell

Linux 计划任务(定时任务)

常用的 crontab 定时任务的写法

<<-

The - option to mark a here document limit string (<<-LimitString) suppresses leading tabs (but not spaces) in the output.
This may be useful in making a script more readable.

C

sizeof

C provides an unary sizeof operator to get the size of the operand (in bytes). The following program uses sizeof operator to print the size of the fundamental types.

The sizeof is a keyword, but it is a compile-time operator that determines the size, in bytes, of a variable or data type.

You can find the array length using expression sizeof(arrayName)/sizeof(arrayName[0]), where sizeof(arrayName) returns the total bytes of the array and sizeof(arrayName[0]) returns the bytes of first element.

C Programming Language Basics

C 语言中你想不到的一些问题

Python

取出从小到大的一组数中的连续自然数
slist = []
file = open("numbers.txt", "r")
for line in file:
    slist.append(line.strip('\n'))

file.close()

s = slist[0]

def displays(strings):
    if strings.find(',') > 0:
        print(strings)

for i in range(1, len(slist)):
    if int(slist[i]) == int(slist[i-1]) + 1:
        s += ',' + slist[i]
    else:
        displays(s)
        s = slist[i]
displays(s)
积水问题
def calculate(testcase):
    p_l = 0
    p_r = len(testcase) - 1
    max_l = testcase[p_l]
    max_r = testcase[p_r]

    volume = 0
    while p_r > p_l :
        if max_l < max_r:
            p_l = p_l + 1
            if testcase[p_l] >= max_l:
                max_l = testcase[p_l]
            else:
                volume = volume + (max_l - testcase[p_l])
        else:
            p_r = p_r - 1
            if testcase[p_r] >= max_r:
                max_r = testcase[p_r]
            else:
                volume = volume + (max_r - testcase[p_r])

    return volume

testcase_1 = [2,5,1,2,3,4,7,7,6]
testcase_2 = [2,5,1,3,1,2,1,7,7,6]
testcase_3 = [6,1,4,6,7,5,1,6,4]
print("case %s total volume : %s " % (testcase_1, calculate(testcase_1)))
print("case %s total volume : %s " % (testcase_2, calculate(testcase_2)))
print("case %s total volume : %s " % (testcase_3, calculate(testcase_3)))