Basic C Language Algorithm 41-string matching problem, algorithm 41 String Matching

Source: Internet
Author: User

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.

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.