本文整理汇总了Java中edu.princeton.cs.algs4.StdIn.readString方法的典型用法代码示例。如果您正苦于以下问题:Java StdIn.readString方法的具体用法?Java StdIn.readString怎么用?Java StdIn.readString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.princeton.cs.algs4.StdIn
的用法示例。
在下文中一共展示了StdIn.readString方法的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();
}
示例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();
}
示例3: 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();
}
示例4: 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());
}
示例5: 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();
}
示例6: 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);
}
}
示例7: 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());
}
}
示例8: main
import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
/** Test client.
* Reads a sequence of strings from the standard input.
* Builds a symbol table whose keys are the strings read.
* The value of each string is its position in the input stream
* (0 for the first string, 1 for the second, and so on).
* Then prints all the (key,value) pairs.
*/
public static void main(String[] args) {
LinkedListST<String, Integer> st;
st = new LinkedListST<>();
for (int i = 0; !StdIn.isEmpty(); i++) {
String key = StdIn.readString();
st.put(key, i);
}
StdOut.println("isEmpty(): "+st.isEmpty());
StdOut.println("get(E)"+st.get("E"));
StdOut.println("get(\"bola\")"+st.get("bola"));
StdOut.println("size()"+st.size());
StdOut.println("rank(E)"+st.rank("E"));
StdOut.println("Min()"+st.min());
StdOut.println("max()"+st.max());
StdOut.println("ceiling(J)"+st.ceiling("J"));
StdOut.println("floor(J)"+st.floor("J"));
StdOut.println("select(4)"+st.select(4));
StdOut.println("deleteMin()");
StdOut.println("deleteMax()");
st.deleteMin();
st.deleteMax();
for (String s : st.keys())
StdOut.println(s + " " + st.get(s));
}
示例9: main
import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
/**
* Unit tests the {@code MinhaRBT} data type.
*
* @param args the command-line arguments
*/
public static void main(String[] args) {
MinhaRBT<String, Integer> st = new MinhaRBT<String, Integer>();
for (int i = 0; !StdIn.isEmpty(); i++) {
String key = StdIn.readString();
st.put(key, i);
StdOut.println("Height : "+st.eagerHeight);
}
StdOut.println("AvgSearchHit : "+st.averageSearchHit());
StdOut.println("AvgSearchMiss : "+st.averageSearchMiss());
StdOut.println("Calculated Height = "+st.height());
StdOut.println("Calculated size = "+st.size());
int k = 0;
for (String s : st.keys()){
if(k > 10) break;
StdOut.println(s + " ");
k++;
}
/*
for (String s : st.keys())
StdOut.println(s + " " + st.get(s));
StdOut.println();
*/
}
示例10: main
import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
MinhaBST<String, Integer> st = new MinhaBST<>();
for (int i = 0; !StdIn.isEmpty(); i++) {
String key = StdIn.readString();
st.put(key, i);
StdOut.println("Height : "+st.eagerHeight);
}
StdOut.println("AvgSearchHit : "+st.averageSearchHit());
StdOut.println("AvgSearchMiss : "+st.averageSearchMiss());
StdOut.println("Calculated Height = "+st.height());
StdOut.println("Calculated size = "+st.size());
StdOut.println("Max = "+st.max());
int k = 0;
for (String s : st.keys()){
if(k > 10) break;
StdOut.println(s + " ");
k++;
}
/*
for (String s : st.levelOrder())
StdOut.println(s + " " + st.get(s));
StdOut.println();
for (String s : st.keys())
StdOut.println(s + " " + st.get(s));
*/
}
示例11: main
import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
/**
* Unit tests the <tt>MinPQ</tt> data type.
*/
public static void main(String[] args) {
MinPQ<String> pq = new MinPQ<String>();
while (!StdIn.isEmpty()) {
String item = StdIn.readString();
if (!item.equals("-")) pq.insert(item);
else if (!pq.isEmpty()) StdOut.print(pq.delMin() + " ");
}
StdOut.println("(" + pq.size() + " left on pq)");
}
示例12: main
import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
Bag<String> bag = new Bag<String>();
while (!StdIn.isEmpty()) {
String item = StdIn.readString();
bag.add(item);
}
StdOut.println("size of bag = " + bag.size());
for (String s : bag) {
StdOut.println(s);
}
}
示例13: main
import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
/**
* Unit tests the <tt>BinarySearchST</tt> data type.
*/
public static void main(String[] args) {
BinarySearchST<String, Integer> st = new BinarySearchST<String, Integer>();
for (int i = 0; !StdIn.isEmpty(); i++) {
String key = StdIn.readString();
st.put(key, i);
}
for (String s : st.keys())
StdOut.println(s + " " + st.get(s));
}
示例14: main
import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
/**
* Reads in a command-line integer and sequence of words from
* standard input and prints out a word (whose length exceeds
* the threshold) that occurs most frequently to standard output.
* It also prints out the number of words whose length exceeds
* the threshold and the number of distinct such words.
*/
public static void main(String[] args) {
int distinct = 0, words = 0;
int minlen = Integer.parseInt(args[0]);
ST<String, Integer> st = new ST<String, Integer>();
//compute frequency counts
while (!StdIn.isEmpty()) {
String key = StdIn.readString();
if (key.length() < minlen)
continue;
words++;
if (st.contains(key)) {
st.put(key, st.get(key) + 1);
} else {
st.put(key, 1);
distinct++;
}
}
//find a key with the highest frequency
String max = "";
st.put(max, 0);
for (String word : st.keys()) {
if (st.get(word) > st.get(max)) {
max = word;
}
}
StdOut.println(max + " " + st.get(max));
StdOut.println("distinct = " + distinct);
StdOut.println("words = " + words);
}
示例15: main
import edu.princeton.cs.algs4.StdIn; //导入方法依赖的package包/类
public static void main(String[] args) {
SequentialSearchST<String, Integer> st = new SequentialSearchST<>();
for (int i = 0; !StdIn.isEmpty(); i++) {
String key = StdIn.readString();
st.put(key, i);
}
for (String s: st.keys()) {
StdOut.println(s + " " + st.get(s));
}
}