test1.java

来自「三种字符串匹配:BF」· Java 代码 · 共 49 行

JAVA
49
字号
package patternMatching;

public class Test1 {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws java.io.FileNotFoundException {
		long start;
		long end;
			
		start = System.nanoTime();
			String text = ReadIn.readIn("NBA_NIKE新浪竞技风暴_新浪网.htm");
			//System.out.println(text);
		end = System.nanoTime();
		System.out.println("Loading costs:"+(end-start)+"\n");

		
		String strPattern = "大仙:阿泰是无麦时刻最强支柱 没他火箭回旧社会";
		PatternMatcher pattern;
		int result;
		
		System.out.println("BruteForce");
		start = System.nanoTime();
			pattern = new BruteForce(strPattern);
			result = pattern.match(text);
		end = System.nanoTime();
		System.out.println("The pattern "+strPattern+" is found with index of "+result);
		System.out.println("The time cost is "+(end-start)+"\n");
		
		System.out.println("BoyerMoore");
		start = System.nanoTime();
			pattern = new BoyerMoore(strPattern);
			result = pattern.match(text);
		end = System.nanoTime();
		System.out.println("the pattern "+strPattern+" is found with index of "+result);
		System.out.println("The time cost is "+(end-start)+"\n");
		
		System.out.println("KnuthMorrisPratt");
		start = System.nanoTime();
			pattern = new KnuthMorrisPratt(strPattern);
			result = pattern.match(text);
		end = System.nanoTime();
		System.out.println("the pattern "+strPattern+" is found with index of "+result);
		System.out.println("The time cost is "+(end-start)+"\n");
		
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?