Skip to content

Instantly share code, notes, and snippets.

@sadedv
Created March 4, 2016 13:25
Show Gist options
  • Save sadedv/80e845a5dbd2c29213e0 to your computer and use it in GitHub Desktop.
Save sadedv/80e845a5dbd2c29213e0 to your computer and use it in GitHub Desktop.
Java Template (Fast I/O)
import java.util.*;
import java.io.*;
class
{
/************************ SOLUTION STARTS HERE ************************/
private static void solve(FastScanner s1, PrintWriter out){
/*
Start typing your solution here
get input by using "s1" object (It works exactly like Scanner but faster than it)
(eg).
int a = s1.nextInt()
String s = s1.nextLine() //Returns an entire line
String s = s1.next() //Returns only one word
Print output using "out" object
(eg).
out.println("Hello,World!")
*/
}
/************************ SOLUTION ENDS HERE ************************/
/************************ TEMPLATE STARTS HERE ************************/
public static void main(String []args) throws IOException {
FastScanner in = new FastScanner(System.in);
PrintWriter out =
new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
solve(in, out);
in.close();
out.close();
}
static class FastScanner{
public BufferedReader reader;
public StringTokenizer st;
public FastScanner(InputStream stream){
reader = new BufferedReader(new InputStreamReader(stream));
st = null;
}
public String next(){
while(st == null || !st.hasMoreTokens()){
try{
String line = reader.readLine();
if(line == null) return null;
st = new StringTokenizer(line);
}catch (Exception e){
throw (new RuntimeException());
}
}
return st.nextToken();
}
public String nextLine(){
String str = null;
try {
str = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt(){
return Integer.parseInt(next());
}
public long nextLong(){
return Long.parseLong(next());
}
public double nextDouble(){
return Double.parseDouble(next());
}
public char nextChar(){
return next().charAt(0);
}
int[] nextIntArray(int n) {
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
long[] nextLongArray(int n) {
long[] arr = new long[n];
for (int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
public void close(){
try{ reader.close(); } catch(IOException e){e.printStackTrace();}
}
}
/************************ TEMPLATE ENDS HERE ************************/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment