Data Structure and Algorithm Problems
1. Statistics of sports meeting scores
[Problem description]:
There are n schools participating in the games, with school numbers from 1 to n.
The competition is divided into m men's events and W women's events. The project
number is 1 to m for men and m+1 to m+w for women. Take the top five or top three
points for different items; The top five scores are 7, 5, 3, 2 and 1 respectively, and the
top three scores are 5, 3 and 2 respectively; The top five or the top three are set by
students themselves (m<=20, n<=20).
[Implementation requirements]:
(1) You can enter the top three or top five scores of each item;
(2) Be able to count the total score of each school;
(3) It can be sorted and output by school number, total score of school and total
score of male and female groups;
(4) You can query the status of a school project by school number; You can query
the top three or top five schools by project number;
(5) Data is stored in files and can be queried at any time;
(6) Input data form and range: you can enter the name of the school and the
name of the sports event.
[Implementation tips]:
(1) The output has a Chinese prompt, and the scores of each school are integers;
(2) Each function can have a menu, and users can implement relevant functions
according to prompts;
(3) The storage structure can be designed based on the adjacency table of the
reference graph.
(4) The design report should include a description of the data testing section.
2. Student Performance Management System
[Problem description]:
Existing student grade information file 1 (1. txt), with the following content
name Student ID Chinese mathematics English
ZhangMingMing 01 67 78 82
LiChengYou 02 78 91 88
ZhangHuiCan 03 68 82 56
WangLu 04 56 45 77
ChenDongMing 05 67 38 47
Student grade information file 2 (2. txt), with the following content:
name Student ID Chinese mathematics English
ChenGuo 31 57 68 82
LiMingHua 32 88 90 68
ZhangMingDong 33 48 42 56
LiMingGuo 34 50 45 87
ChenDaoLiang 35 47 58 77
[Implementation requirements]:
Try to write a management system with the following requirements:
(1) Implement merging of data from two files to generate a new file 3. txt
(2) Extract students with make-up exams from the three subjects and save them
in a new file 4.txt
(3) Sort the data in the merged file 3. txt in descending order of total score (using
at least two sorting methods)
(4) After inputting a student's name, it is possible to find the information of this
student and output the results (using at least two search methods)
(5) Require the use of structures, chains, or arrays to achieve the above
requirements
3. Drug sales statistics system for pharmacies
[Problem description]:
Design a system to enable pharmaceutical companies to regularly collect statistics
on the sales records of various drugs, and rank them based on drug numbers, unit
prices, sales volume, or sales volume.
[Implementation requirements]:
In this design, the information records of each drug are first read out from the
data file and stored in the sequence table. The information of each drug includes: drug
number, drug name, drug unit price, sold quantity, and sales amount. The drug number
consists of 4 digits, using a mixture of letters and numbers, such as A125. The first digit
is a capital letter, and the last three digits are numbers. When sorting by drug number,
the cardinality sorting method can be used. When sorting the unit price, sales volume,
or sales volume of each drug, multiple sorting methods can be used, such as direct
insertion sorting, bubble sorting, quick sorting, and direct selection sorting. In this
design, the bubble sorting method is used to sort the unit price, the fast sorting
method is used to sort the sales volume, and the heap sorting method is used to sort
the sales amount.
[Implementation tips]:
Definition of element types for drug information:
typedef struct node
{char num [4]; /* Drug number*/
char name [10] /* Drug name*/
float price /* Unit price of drugs*/
int count /* Sales quantity*/
float sale /* Sales revenue of this drug*/
}DataType;
Definition of the order table for storing drug information:
typedef struct
{ DataType r[MaxSize];
int length;
}SequenList;
4. Huffman encoder/decoder issues:
Problem Description
Using Huffman encoding for information communication can greatly improve channel
utilization, shorten information transmission time, and reduce transmission costs.
However, this requires pre encoding the data to be transmitted through an encoding
system at the sending end; Decode (restore) the transmitted data at the receiving
end.
Implementation Requirements
The system should have the following functions:
(1) Initialization. Read in the character set size n, n characters, and m weights from
the terminal, establish a Huffman tree, and store it in the file hfmtree.
(2) Coding. Encode the text in the file tobetras using the already built Huffman tree
(read in from the file hfmtree if not in memory), and then save the results in the file
codefile.
(3) Decoding. Decode the code in the file codefile using the established Huffman
tree, and store the results in the file textfile.
(4) Build a Huffman tree using the actual statistical data of the character set and
frequency given in the table below, and implement the encoding and decoding of the
following message: "This Program IS MY FAVORITE".
Implementation Tips
You can divide the program into three modules according to the requirements of the
question, design it as a menu mode, and return to the menu after executing one
module each time. In addition to the initialization process, the disk file data is read
once during each execution. This is because if the initialization process (1) has not
been carried out after the program is executed, in order to ensure the smooth
progress of subsequent operations, the work can be carried out by reading old data.
For example, if the character set and weight data required for the program's work are
fixed, just perform an initial (1) normalization operation during program installation.
When running the program again, no matter which operation is performed, the
required data can be read into memory.
character A B C D E F G H I J K L M
Frequency 64 13 22 32 103 21 15 47 57 1 5 32 20
character N O P Q R S T U V W X Y 2
Frequency 57 63 5 1 48 51 80 23 8 18 1 16 1
5. Campus Tour Guide Program
Problem Description
Use an undirected network to represent the campus scenic spot plan of your school.
The vertices in the map represent the main scenic spots, storing information such as
the number, name, and introduction of the scenic spots. The edges in the map
represent the roads between the scenic spots, storing information such as path
length. It is required to be able to answer questions about the introduction of scenic
spots, tourist routes, etc.
Design Requirements
The design requirements are as follows:
(1) Design a campus scenic spot plan for your school;
(2) Search for relevant information about various tourist attractions;
(3) Search for the shortest path between any two scenic spots in the graph.
(4) Add, delete, and update information about attractions and roads.
6. Analogue calculators - Solution of arithmetic expressions
Problem Description
Given an arithmetic expression, calculate the final result through the program.
Implementation Requirements
(1) Numeric value: includes integers and real numbers, and numerical values can
have positive or negative signs.
(2) Operators: positive sign, negative sign, addition, subtraction, multiplication,
division, modulus, and multiplication, which can include parentheses.
Implementation Tips
(1) Input the required arithmetic expression from the keyboard;
(2) Using a stack structure for solving arithmetic expressions;
(3) Able to determine the correctness of arithmetic expressions;
(4) Provide a prompt for incorrect expressions;
(5) Provide the final result for the correct expression;
7. 7. Article editing
Problem Description
Function: Input - page text, the program can count the number of words, numbers,
Spaces. Statically store page articles with a maximum of 80 characters per line,
Design Requirements
(1) Counting the number of English letters and Spaces and the total number of words
in the entire article;
(2) counting the number of times a string appears in the article, and output the
number of times;
(3) Deleting a substring and moving the following characters forward.
Implementation Tips
The storage structure uses linear table, and realizes the corresponding function with
several sub-functions respectively.
Form and range of input data: You can enter upper and lower case letters, any
number, and punctuation marks.
Output form:
(1) Output each line of characters entered by the user in a branch;
(2) Output "Total number of letters", "number of digits", "number of Spaces", "total
word count of the article" in 4 lines;
(3) Output the article after deleting a string;
8. 8. Parking lot management
Problem Description
There is a long and narrow parking lot for n cars, which has only one gate for vehicles
to enter and exit. Vehicles will be parked from the bottom of the parking lot facing the
gate in the morning and evening of their arrival time (the first car to arrive first will be
placed at the bottom of the parking lot). If the parking lot is full of n cars, subsequent
vehicles can only wait on the service road outside the parking lot gate, and once the
car in the parking lot has left, the first car in line on the service road enters the parking
lot. If a car in the parking lot wants to leave, the cars that enter the parking lot after it
must first exit the parking lot to make way for it, and after it has left the parking lot,
these vehicles will enter in the original order. When leaving the parking lot, each car
should be paid according to the length of time it stays in the parking lot. If a vehicle
parked on the service road is about to leave before entering the parking lot, it is
allowed to leave without charging for parking and remains in the order of waiting
vehicles on the service road. A program was developed to simulate the management
of the parking lot.
Implementation Requirements
The program is required to output the parking location of each vehicle upon arrival (in
the parking lot or on the service road), as well as the amount of money a vehicle should
pay when it leaves the parking lot and the time it stays in the parking lot.
Implementation Tips
The analog input information format of the car can be rewind/departure, the license
plate number of the car, the time of arrival of 1 high). For example, (A, 1, 5) means that
the number 1 car arrives at time 5, and (O, 5, 20) means that the number 5 car leaves
at time 20. The whole program can end when the input information is (E 0, 0j). This
problem can be solved with money and queues. Design well to implement a traffic
advisory system.
9. 9. hash table design and implementation
Problem Description
Design hash table to realize phone number search system.
Basic Requirements
(1) Each record shall have the following data items: telephone number, user name,
address;
(2) Input each record from the keyboard, and create a hash table with the keywords of
phone number and user name respectively;
(3) Adopt certain methods to resolve conflicts;
(4) Find and display records for a given phone number; (5) Finds and displays records
for a given user name.
Progress to complete content
(1) The perfection of system functions;
(2) Design different hash functions and compare the collision rate;
(3) On the premise that the hash function is determined, try different types of conflict
handling methods to investigate the change of the average search length.