2020-Review

1. Programming

1. Write a function to realize the function of decimal to binary conversion. The input of the function is a decimal number, and the output is a binary number, such as input 37, and the output is 100101

#include <stdio.h>
// 编写一个函数实现十进制向二进制转换的功能,函数的输入为一个十进制数,输出为一个二进制数,如输入37,输出为100101
void transfer(int num){
    
    
    if(num>=2)
        transfer(num/2);
    printf("%d",num%2);
    return;
}
int main(void) {
    
    
    int num = 37;
    transfer(num);
    return 0;
}

2. Please write a sorting algorithm to sort the numbers x[n], and the time complexity is not higher than O(nlogn).

#include <stdio.h>
// 快速排序
int partition(int x[],int begin,int end){
    
    
    int pivot = x[begin];
    while (begin<end) {
    
    
        while (begin<end&&x[end]>=pivot) end--;
        x[begin] = x[end];
        while (begin<end&&x[begin]<=pivot) begin++;
        x[end] = x[begin];
    }
    x[begin] = pivot;
    return begin;
}

void Qsort(int x[],int begin,int end){
    
    
    if(begin<end){
    
    
        int mid = partition(x,begin,end);
        Qsort(x,begin, mid-1);
        Qsort(x,mid+1,end);
    }
}

int main(void) {
    
    
    int x[5] = {
    
    1,3,5,2,4};
    Qsort(x,0,4);
    for (int i=0;i<5;i++) {
    
    
        printf("%d ",x[i]);
    }
    return 0;
}

2. Operating system

3. There are periodic real-time tasks A and B: the execution time of task A is 10ms, and it is executed every 20ms; the execution time of task B is 25ms, and it is executed every 50ms. At time 0, A1 and B1 arrive at the same time. The deadline for each task is before the arrival of the next task of the same type

insert image description here

(1) In accordance with the general principles of periodic tasks, please give the deadlines for A3 and B2.

60和100

(2) Please give the slack of A1 task and B1 task at time 0.

10和25

(3) According to the lowest slack first algorithm, draw the execution process diagram of each task.
insert image description here

4. Suppose there are three threads P, Q and R in a process, all three threads call a function to perform a specific function, and then update a global (shared) variable count, as shown in the figure below, please define a semaphore and coordinate these three Processes are executed in the following order: QS1 is executed earlier than PS1; PS1 is executed earlier than RS1; QS2 is executed later than RS1; PS2 and RS2 are executed later than QS2. Please define a suitable semaphore or lock mechanism and insert codes in P, Q, and R to realize the above execution sequence and update count.
insert image description here
The order of execution is as follows, and exclusive access to count is maintained.

QS1
PS1
RS1
QS2
PS2
RS2

Define global variables first

semaphore p1 = 0,p2 = 0,r1 = 0,r2 = 0,q2 = 0,mutex = 1;

P:

p(p1)
PS1()
v(r1)

p(p2)
PS2()

p(mutex)
count = count + 3
v(mutex)

Q

QS1()
v(p1)

p(q2)
QS2()
v(p2)
v(r2)

p(mutex)
count = count - 2
v(mutex)

R

p(r1)
RS1()
v(q2)

p(r2)
RS2()

p(mutex)
count = count + 5
v(mutex)

3. Computer network

6. Describe the process that the user goes through after entering www.sict.ac.cn in the browser to the page displayed in the browser.

1、浏览器根据输入的域名进行DNS解析
2、根据解析到的IP地址访问对应的服务器
3、TCP3次握手建立连接
4、用户申请资源
5、在收到申请后,给用户分配资源
6、浏览器根据得到的资源进行解析和渲染
7、TCP4次挥手进行告别,断开连接

7. A company sets up its headquarters in City A and a branch in City B. There are 260 devices in the headquarters that need to be connected to the Internet for broadband Internet access. Please answer the following questions:
(1) How can a fixed IP in segment C allow all 260 devices in the headquarters to access the Internet. What equipment needs to be added and what functions can be realized?
(2) If 260 devices at the headquarters and 20 devices at the branch are to be able to access each other, what devices need to be added and what functions are needed to implement network planning at the branch and the headquarters?
(3) 260 devices in the headquarters, plus the reserved space for 50 devices, if the addresses of these devices are planned into a local area network (LAN), how should the address and subnet mask of the LAN be planned?
What problems will be caused by too many devices in a LAN, and how to solve them?
(4) What problems will be caused by too many devices in a LAN, and how to solve them?

(The answer to this question is not sure)
(1) Need to add NAT (Network Address Translation)

(3) A total of 310 devices, the number of hosts needs 9 bits to represent ( 2 9 = 512 > 310 2^9 = 512>31029=512>310 ) So there are 32 bits in total, the first 23 bits are the subnet number, and the last 9 bits are the host number. The subnet mask should be 255.255.254.0
(4) There are too many hosts in the same conflict domain, and the probability of conflict will increase. You can use a bridge or switch to isolate the conflict domain.

Guess you like

Origin blog.csdn.net/Kilig___/article/details/129665679