Skip to content

Instantly share code, notes, and snippets.

@ducquoc
Created December 30, 2024 04:12
Show Gist options
  • Save ducquoc/febef09c34dbaf2ab302b6330b407ef9 to your computer and use it in GitHub Desktop.
Save ducquoc/febef09c34dbaf2ab302b6330b407ef9 to your computer and use it in GitHub Desktop.
Delegate Quick Scanner
//import java.io.*; import java.util.*;
/**
* Delegate quick Scanner. Example usage: <pre>QScanner scanner = new QScanner(System.in);</pre>
*/
@SuppressWarnings({"unused", "Duplicates"}) //noinspection Duplicates
public class QScanner {
java.io.BufferedReader br; java.util.StringTokenizer st;
public QScanner() { br = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); }
public QScanner(java.io.InputStream is) {
br = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.DataInputStream(is)));
}
public String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new java.util.StringTokenizer(br.readLine());
} catch (java.io.IOException e) { e.printStackTrace(); }
}
return st.nextToken();
}
public int nextInt() { return Integer.valueOf(next()); }
public long nextLong() { return Long.valueOf(next()); }
public double nextDouble() { return Double.valueOf(next()); }
public void close() {
if (br != null) { try { br.close(); } catch (java.io.IOException e) { e.printStackTrace(); } }
}
}
@ducquoc
Copy link
Author

ducquoc commented Dec 30, 2024

Java template "input scanner" for coding challenges that need quick input.
It is useful for competitive programming (SPOJ, CodeForges, VNOJ, Timus, AtCoder, UVA, USACO, Kattis, TopCoder, CodeChef, HackerEarth, Kaggle, ...),
and also useful for interview grinders (HackerRank/LeetCode/GFG/Codingame/Codility/TestDome/CodeSignal/Codecademy/Codewars/EDABit/BitDegree/...)

@ducquoc
Copy link
Author

ducquoc commented Dec 30, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment