Program daily (2): Delete sub-string in the string

xiaoxiao2021-03-06  40

EX: String Delete Subsidence Date: Jan. 8th, 2005 Idea: An example of deleting a character from a string, from this example, extending a character to a string. Analysis: Delete a character C from a string S: 1. Use two variables I, J indicate the source string next character's index and target string next character's index.2. Traverse source string Each character, take any of these characters, if this character does not equal C, save this character, and J plus 1; otherwise, discard this character, J does not change. Extending this idea, you can implement the sub-string from the string, the pseudo code is: 1. Use two variables I, J represent the index of the source string next character, respectively, the next character of the next character, respectively. Set a logo, indicating that there is a matching string existence. 2.FOR (any character string in the source string) IF (string from this character and string matching string matching required) flag bit = true ELSE flag = false IF (flag = fake) Save this character, and J plus 1; otherwise discard this character, J does not change the following is C code, implement the above ideas: void squeeze (char S []), char T []) {Int i, j, k; i = j = k = 0; int flag = 0; for (i = j = 0; s [i]! = '/ 0'; i) {for (k = 0; t [k]! = '/ 0'; K) {IF (S [i K] == T [K]) FLAG = 1; ELSE {FLAG = 0; Break;}}} (! Flag) s [J ] = S [i];} s [ J] = '/ 0';} This code has not been debugged by temporary, I wrote :)

转载请注明原文地址:https://www.9cbs.com/read-71670.html

New Post(0)