├── KMP.cpp ├── KMP.exe ├── README.md └── kmp666.txt /KMP.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njuptlogic/KMP_data-structure-algorithm-design-/HEAD/KMP.cpp -------------------------------------------------------------------------------- /KMP.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/njuptlogic/KMP_data-structure-algorithm-design-/HEAD/KMP.exe -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KMP 文本查找与统计工具 2 | 3 | 此工具基于 **C++** 实现,结合 **KMP 算法**,可以快速查找文本文件中指定单词的位置及出现次数。程序会逐行读取文本内容,并统计指定单词在每一行的出现次数及总计。 4 | 5 | ## 功能说明 6 | 7 | 1. **支持多个单词查找** 8 | - 用户可以输入多个单词,程序会分别统计每个单词的出现位置及次数。 9 | 10 | 2. **基于 KMP 算法** 11 | - 通过高效的 KMP 算法查找指定单词,避免暴力查找带来的性能问题。 12 | 13 | 3. **文件动态读取** 14 | - 用户可自由选择读取的文本文件,若文件路径错误可重新输入。 15 | 16 | 4. **详细统计结果** 17 | - 显示每个单词在每一行的出现次数及总次数。 18 | 19 | ## 使用方法 20 | 21 | ### 1. 编译与运行 22 | 双击以下程序即可运行: 23 | ``` 24 | KMP.exe 25 | -------------------------------------------------------------------------------- /kmp666.txt: -------------------------------------------------------------------------------- 1 | Let there is only a parking lot can be parked n cars in the narrow channel, and only a gate can be used to enter and exit the car. 2 | Cars in the parking lot according to the order of arrival of vehicles, in order from north to south (the gate at the southernmost end, 3 | the first arrival of the first car parked at the northernmost end of the car park); 4 | 5 | If the car park has been full of n cars, the later cars can only be waiting outside the gate on the right-of-way in turn, once a car to drive away, 6 | then the row of the right-of-way can be the first car to drive into the parking lot when a car to leave, after it drives into the parking lot to make way for it. 7 | 8 | When a car in the parking lot to leave, after it into the vehicle must first exit the car park for it to make way for the car to drive out of the gate, other vehicles 9 | and then enter the car park in the original order; each car parked in the car park when it leaves the parking lot must be according to the length of time it stays to pay the fee. 10 | Try to prepare a simulation program for a parking lot that manages according to the above requirements. The parking lot is simulated by a linear table, 11 | the right of-way outside the parking lot is simulated by a queue, and the simulation is managed according to a sequence of input data read in from a terminal. 12 | 13 | Each set of input data consists of three data items car arrival or departure information, car license plate number, and arrival or departure moment. 14 | The arrival or departure moment. For each set of input data after the operation of the output information is if the vehicle arrives, 15 | the output of the car in the parking lot or on the right-of-way parking position; if the vehicle is leaving, the output of the car in the parking lot to stay in the time and should be paid the fee (in the right-of-way to stay in the time of no charge). 16 | The linear table is implemented as a sequential structure and the queue is implemented as a chained table structure. --------------------------------------------------------------------------------