当前位置: 首页>>代码示例>>Java>>正文


Java StdIn类代码示例

本文整理汇总了Java中edu.princeton.cs.algs4.StdIn的典型用法代码示例。如果您正苦于以下问题:Java StdIn类的具体用法?Java StdIn怎么用?Java StdIn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StdIn类属于edu.princeton.cs.algs4包,在下文中一共展示了StdIn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
    ResizingArrayStack<String> stack = new ResizingArrayStack<String>();
    while (!StdIn.isEmpty()) {
        String item = StdIn.readString();
        if (!item.equals("-")) stack.push(item); 
        else if (stack.isEmpty())  StdOut.println("BAD INPUT"); 
        else                       StdOut.print(stack.pop() + " ");
    }
    StdOut.println();

    // print what's left on the stack
    StdOut.print("Left on stack: ");
    for (String s : stack) {
        StdOut.print(s + " ");
    }
    StdOut.println();
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:18,代码来源:ResizingArrayStack.java

示例2: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
    ResizingArrayQueue<String> q = new ResizingArrayQueue<String>();
    while (!StdIn.isEmpty()) {
        String item = StdIn.readString();
        if (!item.equals("-")) q.enqueue(item); 
        else if (q.isEmpty())  StdOut.println("BAD INPUT"); 
        else                       StdOut.print(q.dequeue() + " ");
    }
    StdOut.println();

    // print what's left on the stack
    StdOut.print("Left on queue: ");
    for (String s : q) {
        StdOut.print(s + " ");
    }
    StdOut.println();
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:18,代码来源:ResizingArrayQueue.java

示例3: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
/**
*  client program
*  takes a command-line integer k; reads in a sequence of strings from standard input using StdIn.
* readString(); and prints exactly k of them, uniformly at random. Print each item from the sequence at most once.
*/
public static void main(String[] args) {
	int k = Integer.parseInt(args[0]);

	RandomizedQueue<String> queue = new RandomizedQueue<>();
	
	while (!StdIn.isEmpty()) {
		queue.enqueue(StdIn.readString());
	}

	int cnt = -1;

	for (String s : queue) {
		if (++cnt == k)
			break;

		StdOut.println(s);
	}
}
 
开发者ID:DCMMC,项目名称:Java-Algorithms-Learning,代码行数:24,代码来源:Permutation.java

示例4: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {		
	String[] a = StdIn.readAllStrings();
	
	long start = System.currentTimeMillis();
	Quick3string.sort(a);
	long end = System.currentTimeMillis();
	System.out.println(end - start);
	
	/*
	long start = System.currentTimeMillis();
	MSD.sort(a);
	long end = System.currentTimeMillis();
	System.out.println(end - start);
	*/
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:16,代码来源:CompareAlgs.java

示例5: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
	In in = new In(args[0]);
	int context = Integer.parseInt(args[1]);
	
	String text = in.readAll().replaceAll("\\s+", " ");
	int N = text.length();
	SuffixArray sa = new SuffixArray(text);
	while (StdIn.hasNextChar()) {
		String q = StdIn.readLine();
		for (int i = sa.rank(q); i < N && sa.select(i).startsWith(q); i++) {
			int from = Math.max(0, sa.index(i) - context);
			int to = Math.min(N-1, from + q.length() + 2*context);
			StdOut.println(text.substring(from,to));
		}
	}
	
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:18,代码来源:KWIC.java

示例6: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
/**
 * Unit tests the <tt>SymbolGraph</tt> data type.
 */
public static void main(String[] args) {
    String filename  = args[0];
    String delimiter = args[1];
    SymbolGraph sg = new SymbolGraph(filename, delimiter);
    Graph G = sg.G();
    while (StdIn.hasNextLine()) {
        String source = StdIn.readLine();
        if (sg.contains(source)) {
            int s = sg.index(source);
            for (int v : G.adj(s)) {
                StdOut.println("   " + sg.name(v));
            }
        }
        else {
            StdOut.println("input not contain '" + source + "'");
        }
    }
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:22,代码来源:SymbolGraph.java

示例7: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
    int max = Integer.parseInt(args[0]);
    FixedCapacityStackOfStrings stack = new FixedCapacityStackOfStrings(max);
    while (!StdIn.isEmpty()) {
        String item = StdIn.readString();
        if (!item.equals("-")) stack.push(item); 
        else if (stack.isEmpty())  StdOut.println("BAD INPUT"); 
        else                       StdOut.print(stack.pop() + " ");
    }
    StdOut.println();

    // print what's left on the stack
    StdOut.print("Left on stack: ");
    for (String s : stack) {
        StdOut.print(s + " ");
    }
    StdOut.println();
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:19,代码来源:FixedCapacityStackOfStrings.java

示例8: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
    Deque<String> op = new LinkedList<String>();
    Deque<Double> val = new LinkedList<Double>();

    while (!StdIn.isEmpty()) {
        String s = StdIn.readString();
        if (s.equals("(")) ;
        else if (s.equals("+")) op.addFirst("+");
        else if (s.equals("*")) op.addFirst("*");
        else if (s.equals("-")) op.addFirst("-");
        else if (s.equals("/")) op.addFirst("/");
        else if (s.equals(")")) {
            String operator = op.removeFirst();
            Double n1 = val.removeFirst();
            Double n2 = val.removeFirst();
            if (operator.equals("+")) val.addFirst(n1 + n2);
            else if (operator.equals("*")) val.addFirst(n1 * n2);
            else if (operator.equals("-")) val.addFirst(n2 - n1);
            else if (operator.equals("/")) val.addFirst(n2 / n1);
        }
        else val.addFirst(Double.parseDouble(s));      
    }
    System.out.println(val.removeFirst());
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:25,代码来源:Evaluate.java

示例9: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
    int max = Integer.parseInt(args[0]);
    FixedCapacityStack<String> stack = new FixedCapacityStack<String>(max);
    while (!StdIn.isEmpty()) {
        String item = StdIn.readString();
        if (!item.equals("-")) stack.push(item); 
        else if (stack.isEmpty())  StdOut.println("BAD INPUT"); 
        else                       StdOut.print(stack.pop() + " ");
    }
    StdOut.println();

    // print what's left on the stack
    StdOut.print("Left on stack: ");
    for (String s : stack) {
        StdOut.print(s + " ");
    }
    StdOut.println();
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:19,代码来源:FixedCapacityStack.java

示例10: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
/**
 * Reads in a sequence of strings from standard input; insertion sorts them;
 * and prints them to standard output in ascending order.
 */
public static void main(String[] args) {
    String[] a = StdIn.readAllStrings();
    Insertion.sort(a);
    //Insertion.sort(null); //not handled
    show(a);
}
 
开发者ID:yunfeiguo,项目名称:bioinfo_toolbox,代码行数:11,代码来源:Insertion.java

示例11: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
    BinarySearchSymbolTable<String, Double> scoresMap = new BinarySearchSymbolTable<>(2);
    scoresMap.put("A+", 4.33);
    scoresMap.put("A", 4.00);
    scoresMap.put("A-", 3.67);
    scoresMap.put("B+", 3.33);
    scoresMap.put("B", 3.00);
    scoresMap.put("B-", 2.67);
    scoresMap.put("C+", 2.33);
    scoresMap.put("C", 2.00);
    scoresMap.put("C-", 1.67);
    scoresMap.put("D", 1.00);
    scoresMap.put("F", 0.00);

    String[] grades = StdIn.readAllLines();
    double gpa = new Exercise1().computeGPA(scoresMap, grades);
    StdOut.printf("GPA: %.2f", gpa);
}
 
开发者ID:reneargento,项目名称:algorithms-sedgewick-wayne,代码行数:19,代码来源:Exercise1.java

示例12: readInputAndBuildConcordance

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
private Map<String, List<Integer>> readInputAndBuildConcordance() {
    int wordIndex = 0;
    Map<String, List<Integer>> concordanceMap = new HashMap<>();

    while (StdIn.hasNextLine()) {
        String wordLine = StdIn.readLine();
        String[] words = wordLine.split(" ");

        for(String word : words) {
            if(!concordanceMap.containsKey(word)) {
                concordanceMap.put(word, new ArrayList<>());
            }
            concordanceMap.get(word).add(wordIndex);

            wordIndex++;
        }
    }

    return concordanceMap;
}
 
开发者ID:reneargento,项目名称:algorithms-sedgewick-wayne,代码行数:21,代码来源:Exercise20_Concordance.java

示例13: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main (String[] args) {
        Exercise40_MoveToFront<Character> moveToFront = new Exercise40_MoveToFront<>();

        while (StdIn.hasNextChar()){
            moveToFront.insert(StdIn.readChar());
        }

        // Test data
//        moveToFront.insert('a');
//        moveToFront.insert('b');
//        moveToFront.insert('c');
//        moveToFront.insert('d');
//        moveToFront.insert('c');
//        moveToFront.insert('d');
//        moveToFront.insert('z');

        for (char character : moveToFront) {
            StdOut.println(character);
        }
    }
 
开发者ID:reneargento,项目名称:algorithms-sedgewick-wayne,代码行数:21,代码来源:Exercise40_MoveToFront.java

示例14: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
    int k = Integer.parseInt(args[0]);
    RandomizedQueue<String> queue = new RandomizedQueue<>();

    while (!StdIn.isEmpty()) {
        queue.enqueue(StdIn.readString());
    }

    Iterator<String> iterator = queue.iterator();
    for (int i = 0; iterator.hasNext() && i < k; i++) {
        StdOut.println(iterator.next());
    }
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:14,代码来源:Permutation.java

示例15: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
    int M = Integer.parseInt(args[0]);
    MinPQ<Transaction> pq = new MinPQ<>();

    while (StdIn.hasNextLine()) {
        String line = StdIn.readLine();
        Transaction item = new Transaction(line);

        pq.insert(item);
        if (pq.size() > M) pq.delMin();
    }
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:13,代码来源:TopM.java


注:本文中的edu.princeton.cs.algs4.StdIn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。