Created
December 30, 2024 04:12
-
-
Save ducquoc/febef09c34dbaf2ab302b6330b407ef9 to your computer and use it in GitHub Desktop.
Delegate Quick Scanner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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(); } } | |
} | |
} |
The quick scanner can be customized a bit to adapt to your need. Examples:
https://github.com/ducquoc/euler-fun/blob/master/euler/src/main/java/vn/ducquoc/euler/HR034.java#L50
https://raw.githubusercontent.com/dqonline/pic/main/u/TECH/VNOJ_LIS_sample.png
...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/...)