Ejemplo n.º 1
0
    /**/ public static void main(string[] strarr)
    {
        In          @in         = new In(strarr[0]);
        int         num         = Integer.parseInt(strarr[1]);
        string      text        = java.lang.String.instancehelper_replaceAll(@in.readAll(), "\\s+", " ");
        int         num2        = java.lang.String.instancehelper_length(text);
        SuffixArray suffixArray = new SuffixArray(text);

        while (StdIn.hasNextLine())
        {
            string text2 = StdIn.readLine();
            for (int i = suffixArray.rank(text2); i < num2; i++)
            {
                int num3     = suffixArray.index(i);
                int endIndex = java.lang.Math.min(num2, num3 + java.lang.String.instancehelper_length(text2));
                if (!java.lang.String.instancehelper_equals(text2, java.lang.String.instancehelper_substring(text, num3, endIndex)))
                {
                    break;
                }
                int beginIndex = java.lang.Math.max(0, suffixArray.index(i) - num);
                int endIndex2  = java.lang.Math.min(num2, suffixArray.index(i) + num + java.lang.String.instancehelper_length(text2));
                StdOut.println(java.lang.String.instancehelper_substring(text, beginIndex, endIndex2));
            }
            StdOut.println();
        }
    }
Ejemplo n.º 2
0
    /**
     * Reads a string from a file specified as the first
     * command-line argument; read an integer k specified as the
     * second command line argument; then repeatedly processes
     * use queries, printing all occurrences of the given query
     * string in the text string with k characters of surrounding
     * context on either side.
     *
     * @param args the command-line arguments
     */
    public static void main(String[] args) {
        In in = new In(args[0]);
        int context = Integer.parseInt(args[1]);

        // read in text
        String text = in.readAll().replaceAll("\\s+", " ");
        int n = text.length();

        // build suffix array
        SuffixArray sa = new SuffixArray(text);

        // find all occurrences of queries and give context
        while (StdIn.hasNextLine()) {
            String query = StdIn.readLine();
            for (int i = sa.rank(query); i < n; i++) {
                int from1 = sa.index(i);
                int to1   = Math.min(n, from1 + query.length());
                if (!query.equals(text.substring(from1, to1))) break;
                int from2 = Math.max(0, sa.index(i) - context);
                int to2   = Math.min(n, sa.index(i) + context + query.length());
                StdOut.println(text.substring(from2, to2));
            }
            StdOut.println();
        }
    } 
        /**/
        public static void main(string[] strarr)
        {
            string      str         = strarr[0];
            string      str2        = strarr[1];
            SymbolGraph symbolGraph = new SymbolGraph(str, str2);
            Graph       graph       = symbolGraph.G();

            while (StdIn.hasNextLine())
            {
                string str3 = StdIn.readLine();
                if (symbolGraph.contains(str3))
                {
                    int      i        = symbolGraph.index(str3);
                    Iterator iterator = graph.adj(i).iterator();
                    while (iterator.hasNext())
                    {
                        int i2 = ((Integer)iterator.next()).intValue();
                        StdOut.println(new StringBuilder().append("   ").append(symbolGraph.name(i2)).toString());
                    }
                }
                else
                {
                    StdOut.println(new StringBuilder().append("input not contain '").append(str3).append("'").toString());
                }
            }
        }
Ejemplo n.º 4
0
 /**
  * Interprets the command-line argument as a regular expression
  * (supporting closure, binary or, parentheses, and wildcard)
  * reads in lines from standard input; writes to standard output
  * those lines that contain a substring matching the regular
  * expression.
  *
  * @param args the command-line arguments
  */
 public static void main(String[] args) { 
     String regexp = "(.*" + args[0] + ".*)";
     NFA nfa = new NFA(regexp);
     while (StdIn.hasNextLine()) { 
         String line = StdIn.readLine();
         if (nfa.recognizes(line)) {
             StdOut.println(line);
         }
     }
 } 
Ejemplo n.º 5
0
    /**
     *  Reads a sequence of transactions from standard input; takes a
     *  command-line integer m; prints to standard output the m largest
     *  transactions in descending order.
     *
     * @param args the command-line arguments
     */
    public static void main(String[] args) {
        int m = Integer.parseInt(args[0]); 
        MinPQ<Transaction> pq = new MinPQ<Transaction>(m+1);

        while (StdIn.hasNextLine()) {
            // Create an entry from the next line and put on the PQ. 
            String line = StdIn.readLine();
            Transaction transaction = new Transaction(line);
            pq.insert(transaction); 

            // remove minimum if m+1 entries on the PQ
            if (pq.size() > m) 
                pq.delMin();
        }   // top m entries are on the PQ

        // print entries on PQ in reverse order
        Stack<Transaction> stack = new Stack<Transaction>();
        for (Transaction transaction : pq)
            stack.push(transaction);
        for (Transaction transaction : stack)
            StdOut.println(transaction);
    }