Basic C Language Algorithm 41-string matching problem, algorithm 41 String Matching
// String Matching
/*
========================================================== ======================================
Question: input two strings S, T, and output characters that exist in S but do not exist in T are stored in the new string,
And keep the order in string S, and then display the content of the new string on the screen.
========================================================== ======================================
*/
# Include <stdio. h>
# Include <string. h>
Void main ()
{
Char S [30], T [30], xin [30];
Int I, j, k = 0;
Printf ("string S :");
Gets (S );
Printf ("string T :");
Gets (T );
For (I = 0; I <strlen (S); I ++)
For (j = 0; j <strlen (T); j ++)
If (S [I] = T [j])
S [I] = '';
For (I = 0; I <strlen (S); I ++)
If (S [I]! = '')
Xin [k ++] = S [I];
Xin [k] = '\ 0 ';
Printf ("New String :");
For (I = 0; I <strlen (xin); I ++)
Printf ("% c", xin [I]);
Printf ("\ n ");
}
/*
========================================================== ======================================
Evaluation: equivalent to seeking S-T;
The basic idea is to match the first character in S with all characters in T. If the match is successful
', Otherwise it will not be processed until all characters in S have been matched. Then, replace the non-''characters in S with the original
To save it to the new string in sequence, and output it in the final order.
========================================================== ======================================
*/
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.