Sie sind auf Seite 1von 2

Use BufferedReader it is very very fast than System.out.println()!!

As per codechef wiki 33 BufferedInputStream 39 is the fastest

https://www.codechef.com/wiki/java#IO_in_Java
https://docs.oracle.com/javase/7/docs/api/java/io/BufferedInputStream.html
import java.io.*;
class FastIO
{
static BufferedInputStream in = new BufferedInputStream(System.in);
static int readInt() {
int no = 0;
boolean minus = false;
try {
int a = in.read();
while (a == 32 || a == 10) //10 is newline & 32 is ASCII for space
a = in.read();
if (a == '-') {
minus = true;
a = in.read();
}
while (a != 10 && a != 32 && a != -1) {
no = no * 10 + (a - '0');
a = in.read();
}
}catch (IOException e) {
e.printStackTrace();
}
return minus ? -no: no;
}
static String read() {
StringBuilder str = new StringBuilder();
try {
int a = in.read();
while (a == 32)
a = in.read();
while (a != 10 && a != 32 && a != -1) {
str.append((char)a);
a = in.read();
}
} catch(Exception e) {
e.printStackTrace();
}
return str.toString();
}
public static void main (String[] args) {
/*Accepting input in the format
*<integer> <word>
*/
int no = readInt();
String str = read();
}
}

Apart from Buffered Reader, you might want to take a look at Print Writer also,
it’s considerably faster than System.out.println (I’ve tested it in a Codechef
problem and it reduced the time by 0.08 ~ 0.1 seconds ).
After all output speed is as important as the input speed, isn’t it?
https://www.quora.com/What-is-the-best-way-in-Java-to-take-input-and-write-output-
for-an-Online-Judge

https://codeforces.com/blog/entry/3273

https://hackthejava.wordpress.com/2016/09/16/inputoutput-in-java/

Use BufferedReader it is very very fast than System.out.println()!!

https://www.hackerearth.com/practice/notes/inputoutput-in-javascanner-
bufferedreader-self-made-fast-io/

https://discuss.codechef.com/t/faster-input-in-java/8176

https://www.codechef.com/status/FROGV,shivamsharma

https://www.quora.com/How-can-we-take-fast-input-in-Java

https://stackoverflow.com/questions/7049011/whats-the-fastest-way-to-read-from-
system-in-in-java