001package algs53; // section 5.3 002import stdlib.*; 003/* ************************************************************* 004 * 005 * Compilation: % java System.java 006 * Execution: % java System n 007 * 008 * Search for the string a^N b in the string a^2N 009 * where N = 2^n. 010 * 011 ***************************************************************/ 012 013public class XSystemSearch { 014 015 016 public static void main(String[] args) { 017 args = new String[] { "10" }; 018 int n = Integer.parseInt(args[0]); 019 String txt = "a"; 020 String pat = "a"; 021 for (int i = 0; i < n; i++) { 022 txt = txt + txt; 023 pat = pat + pat; 024 } 025 txt = txt + txt; 026 pat = pat + "b"; 027 // StdOut.println(text); 028 // StdOut.println(query); 029 StdOut.println(txt.indexOf(pat)); 030 } 031}