[Basis of algorithm design and analysis] 6. Brute Force Character matching, algorithm design and analysis matching

Source: Internet
Author: User

[Basis of algorithm design and analysis] 6. Brute Force Character matching, algorithm design and analysis matching

Package com. cutterpoint. gogogo. program ;/****. ** @ copyright: copyright of Fufu software (c) 2015 * @ author xiaof * @ version Revision 1.0.0 * @ see: * @ creation Date: July 15, March 15, 2017 * @ function description: **/public class BruteForceStringMatch {public static int pipei (String t, String p) {// cyclically traverse to t. the number of times the length-p.length int cha = t. length ()-p. length (); char tt [] = t. toCharArray (); char pp [] = p. toCharArray (); for (int I = 0; I <= cha; ++ I) {// matches the circular traversal mode int j = 0; while (j <p. length () & tt [I + j] = pp [j]) {// If the match is successful, the overall backward movement + + j; // if j ++ is followed by the end of the pattern, the return position if (j = p. length () return I; // starting from the position I, the pattern matches the first substring OK} return-1;} public static void main (String [] args) {String t = "cutterpoint"; String p = "point"; System. out. println (BruteForceStringMatch. pipei (t, p ));}}

  

 

 

The efficiency of this method obviously cannot be directly looked at, and there will be corresponding improvements later, such as the kmp Algorithm

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.