Data structure Practice Project--string

Source: Internet
Author: User

This paper is aimed at the data structure Basic Series Network course (4): String.
1. Basic concepts and guidance of strings
2. Sequential storage of strings and its basic operation implementation
3. Sequential storage applications for strings
4. Chain-store and its basic operation implementation
5. String pattern matching (brute-force algorithm)
6. String pattern matching (KMP algorithm)

"Project 1-Build an algorithmic library of sequential strings"
Define the storage structure of the sequential string, implement its basic operations, and complete the test.
Requirements:
1. The header file sqString.h defines the data structure and declares the function used to complete the basic operation. Functions that correspond to basic operations include:

voidStrassign (sqstring &s,CharCstr[]);//string constant CStr assigned to string svoidStrcopy (sqstring &s,sqstring t);//String T Copy to string sBOOLStrequal (sqstring s,sqstring t);//sentence string equalintStrlength (sqstring s);//Find string lengthSqstring Concat (sqstring s,sqstring t);//String ConnectionSqstring SubStr (sqstring s,intIintj);//Sub-stringSqstring Insstr (sqstring s1,intI,sqstring S2);//String insertionSqstring Delstr (sqstring s,intIintj);//String to deleteSqstring Repstr (sqstring s,intIintJ,sqstring t);//String replacementvoidDispstr (sqstring s);//Output string

2. Implement these functions in SqString.cpp
3. Complete the test in the main function, including the following:
(1) Set up string s:abcdefghijklmn and string s1:123
(2) Output string s and s1
(3) Length of output string s
(4) Inserting a string S1 at the 9th character position of string s and generating a string s2
(5) Output string s2
(6) Delete string s 2nd character starting from 5 characters and generate a string s2
(7) Output string s2
(8) Replace the string s 2nd character starting with 5 characters into a string S1 and generate a string s2
(9) Output string s2
(10) Extract string S of the 2nd character starting with 10 characters and produce a string s3
(11) Output string s3
(12) string S1 and string S2 are connected together to produce a string S4
(13) Output string S4
[Reference Solution]

"Project 2-build a chain of algorithmic libraries"
Define the storage structure of the chain string, implement the basic operation of the string, and complete the test.
The specific requirements refer to item 1.
[Reference Solution]

"Item 3-Sequential string algorithm"
Use sequential storage to store strings, implement the following algorithms and test:
(1) Try to write the algorithm to replace all characters in the string s with values of C1 into characters with a value of C2:
void Trans(SqString *&s, char c1, char c2);

(2) Try to write an algorithm that implements all characters of a known string to be rearranged backwards. If the abcdef is changed to FEDCBA.
void Invert(SqString &s)
(3) Remove all characters whose value equals C from string S. If you remove ' e ' from the message, you get MSSAG.
void DellChar(SqString &s, char c)
(4) There are two strings S1 and S2, design an algorithm to find a such string, the characters in the string are S1 and S2 common characters. The so-called common substring is a character that is composed of characters in the S1, and also in S2. Example S1 is "message" and S2 is "agent", the common substring obtained is "eage".
SqString CommChar(SqString s1,SqString s2);
[Reference Solution]

"Item 4-String Encryption"
A text string can be encrypted using a pre-compiled character mapping table. For example, set the character mapping table to:

 abcdefghijklmnopqrstuvwxyz ngzqtcobmuhelkpdawxfyivrsj

The string "Lao he jiao Shu Ju Jie Gou" is encrypted as "ENP BT UMNP Xby uy umt opy".
Design a program to implement encryption, decryption algorithm, the input text is encrypted after the output, and then decrypted and output.
[Reference Solution]

"Item 5-Pattern matching for counts"
Using sequential structure storage strings, write an algorithm that calculates the number of occurrences of a substring in a string, or 0 if the substring does not appear.

Tip: Regardless of the BF pattern matching algorithm, or the KMP algorithm, are found in the substring substr after the exit. To solve this problem, look up the entire string and write down the number of occurrences. Transform the two algorithms.

[Reference Solution]

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Data structure Practice Project--string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.