48 days of intensive written test training——day30

1. Single choice

1. Which of the following statements about threads is wrong ()

A Time-consuming operations use threads to improve program response
B Memory-consuming operations use threads to improve memory utilization
C Multi-CPU systems use threads to increase CPU utilization
D Parallel operations use threads, such as server-side programs in c/s architecture Create a thread for each client request to respond to

Correct answer: B

When a time-consuming operation can be divided into multiple threads and run in parallel, so as to improve the running efficiency of the program, when multiple threads are running in parallel, it is not better than high memory utilization. Multi-threaded parallelism can improve CPU utilization
. The rate
c/s server program can allow a thread to serve a client, typically a tcp server program.

To sum up: Multi-threaded programs can increase CPU utilization, but cannot improve memory utilization, so choose B

 

2. If the block size in the fixed block size file system is set larger, it will cause ().

A better disk throughput and worse disk space utilization
B better disk throughput and better disk space utilization
C worse disk throughput and better disk space utilization
D worse disk Throughput and worse disk space utilization

Correct answer: A

1. If the fixed block size of the disk is set too large, it will cause that when storing small block files, the size of a block is more than enough, and the free space in this block cannot be allocated to other programs, so that the disk The utilization rate will be reduced by
2 and the throughput of the entire disk will be increased at the same time, because the blocks allocated each time are larger than the previous ones, and the allocated space is larger when the number of blocks is the same.

 

3. There are 11 printers in a system, and N processes share printer resources, and each process requires 3 printers. When the value of N does not exceed (), the system will not deadlock.

A 4
B 5
C 6
D 7
Correct answer: B

This kind of problem can be solved with the idea of ​​the philosopher’s dining problem. Each process requires 3 machines, so first give each process 2 machines, and if there is an extra machine, distribute it to a certain process, and release yourself when the process is finished. The resources are used by other processes so that deadlocks do not occur. That is, 2N+1=11, so N=5. When N=4, it is not the maximum value, which does not meet the meaning of the question. When N=6, the resources are not enough, and there may be a deadlock.

 

4. Process scheduling is to select a process from () and put it into operation.

A Ready queue
B Waiting queue
C Job backup queue
D Submission queue
Correct answer: A

Operating system scheduling is to get a process from the ready queue to run.

 

5. Which of the following statements about Cache is incorrect ()

A The purpose of setting Cache is to solve the speed matching problem between CPU and main memory
B The theoretical basis of setting Cache is the locality principle of program access
C Cache and main memory are uniformly addressed, and the address space of Cache belongs to a part of main memory
The functions of D Cache are implemented by hardware and are transparent to programmers

Correct answer: C

C option: Cache is a high-speed small-capacity memory between the central processing unit and the main memory, so it is not part of the main memory

 

6. What is memory jitter (Thrashing) ( )

A Very frequent paging activity
B Very high CPU execution activity
C An extremely long execution process
D An extremely large virtual memory

Correct answer: A

Memory jitter: Frequent replacement of memory pages leads to a sharp drop in the efficiency of the entire system. This phenomenon is called memory jitter.
Jitter is generally caused by poor memory allocation algorithm, too small memory or poor algorithm of the program caused by frequent page transfer from memory

 

7. Among all non-preemptive CPU scheduling algorithms, the average response time of the system is optimal ( )

A Real-time scheduling algorithm
B Short task priority algorithm
C Time slice round-robin algorithm
D First come first serve algorithm

Correct answer: B

1. The short task priority system has the shortest average response time, but it is often impossible to determine the running time of all tasks. 2.
Time slice rotation is suitable for time-sharing systems, but preemption is added to switch processes. The algorithm performance depends on the time slice size and time-sharing
operations System: It is an operating system that enables a computer to serve several, dozens or even hundreds of users at the same time by means of time slice rotation. 3. First come, first
served has the longest average response time. Not suitable for time-sharing operating systems

 

8. Which of the following is wrong about the inode description?

A inode and file are in one-to-one correspondence
B inode can describe the number of blocks occupied by the file
C inode describes the size of the file and the pointer to the data block
D realizes the conversion of the logical structure and physical structure of the file through the inode

Correct answer: A

A: In the case of hard links, multiple files point to the same inode node
1. The inode contains the relevant (meta) information of the file, including the size of the file, the owner of the file, the access permission method of the file, and the type of the file, etc. Important information.
2. The most important content in the inode node table is the disk address table. There are 13 block numbers in the disk address table, and the file will read the corresponding blocks sequentially in the order in which the block numbers appear in the disk address table. File data is stored in "blocks". A block is usually 8 sectors, 4KB.
3. The Linux file system connects the inode node with the file name. Search for the item corresponding to the file name, and thus obtain the corresponding inode node number of the file, and connect the scattered physical blocks of the file into a logical structure of the file through the disk address table of the inode node.

 

9. What is the only basis for file manipulation?

A file name
B file handle
C physical address
Correct answer: B

File descriptor: the return value of the open function, which returns the handle of the currently operating file,
and then reads or writes the file through the file descriptor (file handle)

int open(const char *pathname,int flags,mode_t mode);
ssize_t read(int fd,void *buf,size_t count);
ssize_t write(int fd ,const void *buf,size_t count);

 

10. What is the 3's 4's complement of the decimal number -10?

A 0010
B 1010
C 2122
D 2121
Correct answer: C

Complement code = inverse code + 1, in the computer, use complement code to represent negative numbers. (1) Represented by 0, 1, 2;
(2) When encountering 3-ary;
then the complement of 3-ary numbers is the same as the conversion process of binary. (1) The first ternary representation of 10 is 0101;
B(2) The inversion of the ternary representation of 10 is 2121;
(3) Adding 1 bit to the inverted ternary representation is equal to 2122 ;

 
 

2. Programming

1. The hardest problem

Link

NowCoder lives in an age of danger and intrigue. In order to survive, he first invented the cipher, which was used for messaging in the army. Suppose you are
an officer in a legion and need to decipher the incoming message and provide it
to your general.
The method of message encryption is: for each letter in the original text of the message, replace it with the fifth letter after the letter (for example:
each replaced with the letter F), and other characters remain unchanged. And all letters in the original text of the message are capitalized. The correspondence between the letters in the password and
the letters in the original text is as follows.
Password letter: ABCDEFGHIJKLMNOPQRSTU VWXYZ
Original letter: VWXYZABCDEFGHIJKLMNOP QRSTU

Input description:
The input includes multiple sets of data, one line for each set of data, which is the received ciphertext.
The ciphertext consists only of spaces and capital letters.
Output description:
Corresponding to each set of data, output the decrypted plaintext.

Example 1:
Enter
HELLO WORLD
SNHJ
and output
CZGGJ RJMGY
NICE

correct answer:

#include <stdio.h>
int main() {
    
    
    char c;
    while ((c = getchar()) != EOF){
    
    
        if ('A' <= c && 'Z' >= c) {
    
    
            c = (c > 'E') ? (c - 5) : (c + 21);
        } 
        putchar(c);
    }
    return 0;
}

 

2. Number of factors

Link

A positive integer can be decomposed into a product of one or more arrays. For example, 36=2 2 3*3, which includes two factors of 2 and 3. NowCoder is recently
studying the distribution of the number of factors, and now given a series of positive integers, he hopes you develop a program to output the number of factors of each positive integer.

Input description:
The input includes multiple sets of data.
Each set of data has only one integer n (2≤n≤100000).
Output description:
Corresponding to each integer, output the number of its factors, and each result occupies one line.

Example 1:
Input
30
26
20
Output
3
2
2

correct answer:

#include <iostream>
#include<math.h>
using namespace std;

int main()
{
    
    
    int n, k, i;
    while (cin >> n){
    
    
        k = 0;
        for (i = 2; i <= sqrt(n); i++) {
    
    
            if ((n % i) == 0) {
    
    
                while ((n % i) == 0){
    
    
                    n = n / i;
                }
                k++;
            }
        } 
        if(n != 1)
            k++;
        cout << k << endl;
    } 
    return 0;
}

Guess you like

Origin blog.csdn.net/Ll_R_lL/article/details/128730538