• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java StdIn类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: main

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

    while (!StdIn.isEmpty()) {
        String s = StdIn.readString();
        if (s.equals("-")) StdOut.print(stack.pop());
        else stack.push(s);
    }
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:10,代码来源:Main.java


示例17: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
    int N = StdIn.readInt();
    UF uf = new UF(N);

    while (!StdIn.isEmpty()) {
        int p = StdIn.readInt();
        int q = StdIn.readInt();
        if (!uf.connected(p, q)) {
            uf.union(p, q);
            StdOut.println(p + ' ' + q);
        }
    }
}
 
开发者ID:SkullTech,项目名称:algorithms-princeton,代码行数:14,代码来源:Main.java


示例18: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
	int n = StdIn.readInt();
	int T = StdIn.readInt();
	PercolationStats perStats = new PercolationStats(n, T);
	StdOut.printf("mean                    = %.8f\n", perStats.mean());
	StdOut.printf("stddev                  = %.8f\n", perStats.stddev());
	StdOut.printf("95%% confidence interval = [%.16f, %.16f]", perStats.confidenceLo(),perStats.confidenceHi());
}
 
开发者ID:Lxinyuelxy,项目名称:Princeton_Algorithms,代码行数:9,代码来源:PercolationStats.java


示例19: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
 In in = new In(args[0]);
  Digraph G = new Digraph(in);
  SAP sap = new SAP(G);
  while (!StdIn.isEmpty()) {
      int v = StdIn.readInt();
      int w = StdIn.readInt();
      int length   = sap.length(v, w);
      int ancestor = sap.ancestor(v, w);
      StdOut.printf("length = %d, ancestor = %d\n", length, ancestor);
  }
}
 
开发者ID:Lxinyuelxy,项目名称:Princeton_Algorithms,代码行数:13,代码来源:SAP.java


示例20: main

import edu.princeton.cs.algs4.StdIn; //导入依赖的package包/类
public static void main(String[] args) {
	int k = Integer.parseInt(args[0]);
	RandomizedQueue<String> que = new RandomizedQueue<String>();
	
	while(!StdIn.isEmpty()){
		String item = StdIn.readString();
		que.enqueue(item);
	}
	for(int i = 0; i < k; i++){
		StdOut.println(que.dequeue());
	}
}
 
开发者ID:Lxinyuelxy,项目名称:Princeton_Algorithms,代码行数:13,代码来源:Permutation.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CharsetMapper类代码示例发布时间:2022-05-22
下一篇:
Java NotNullProducer类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap