Java编程在ICPC快速IO实现源码
本文将介绍Java在ICPC快速IO实现方法,下面看看具体代码。
不处理EOF:
importjava.io.OutputStream;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.PrintWriter;
importjava.util.Arrays;
importjava.util.Random;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.util.StringTokenizer;
importjava.io.BufferedReader;
importjava.util.Comparator;
importjava.io.InputStream;
/**
*BuiltusingCHelperplug-in
*Actualsolutionisatthetop
*/
publicclassMain{
publicstaticvoidmain(String[]args){
InputStreaminputStream=System.in;
OutputStreamoutputStream=System.out;
InputReaderin=newInputReader(inputStream);
PrintWriterout=newPrintWriter(outputStream);
TaskDsolver=newTaskD();
solver.solve(1,in,out);
out.close();
}
staticclassTaskD{
publicvoidsolve(inttestNumber,InputReaderin,PrintWriterout){
}
}
staticclassInputReader{
publicBufferedReaderreader;
publicStringTokenizertokenizer;
publicInputReader(InputStreamstream){
reader=newBufferedReader(newInputStreamReader(stream),32768);
tokenizer=null;
}
publicStringnext(){
while(tokenizer==null||!tokenizer.hasMoreTokens()){
try{
tokenizer=newStringTokenizer(reader.readLine());
}catch(IOExceptione){
thrownewRuntimeException(e);
}
}
returntokenizer.nextToken();
}
publicintnextInt(){
returnInteger.parseInt(next());
}
}
}
处理EOF:
importjava.io.OutputStream;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.PrintWriter;
importjava.math.BigInteger;
importjava.util.Arrays;
importjava.util.Random;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.util.StringTokenizer;
importjava.io.BufferedReader;
importjava.util.Comparator;
importjava.io.InputStream;
/**
*BuiltusingCHelperplug-in
*Actualsolutionisatthetop
*/
publicclassMain{
publicstaticvoidmain(String[]args){
InputStreaminputStream=System.in;
OutputStreamoutputStream=System.out;
InputReaderin=newInputReader(inputStream);
PrintWriterout=newPrintWriter(outputStream);
TaskDsolver=newTaskD();
solver.solve(1,in,out);
out.close();
}
staticclassTaskD{
publicvoidsolve(inttestNumber,InputReaderin,PrintWriterout){
while(in.hasNext())
{
inta=in.nextInt();
intb=in.nextInt();
System.out.println(a+b);
}
}
}
staticclassInputReader{
publicBufferedReaderreader;
publicStringTokenizertokenizer;
publicInputReader(InputStreamstream){
reader=newBufferedReader(newInputStreamReader(stream),32768);
tokenizer=null;
}
publicbooleanhasNext(){
while(tokenizer==null||!tokenizer.hasMoreTokens()){
try{
Stringline=reader.readLine();
if(line==null)returnfalse;
tokenizer=newStringTokenizer(line);
}catch(IOExceptione){
thrownewRuntimeException(e);
}
}
returntrue;
}
publicStringnext()
{
returntokenizer.nextToken();
}
publicintnextInt(){
returnInteger.parseInt(next());
}
}
}
总结
以上就是本文的全部内容,希望对大家有所帮助。感谢大家对本站的支持!