Rumah >Java >javaTutorial >Java编程实现在ICPC快速IO的实例详解

Java编程实现在ICPC快速IO的实例详解

黄舟
黄舟asal
2017-09-11 10:27:421423semak imbas

这篇文章主要介绍了Java Fast IO in ICPC实现源码,具有一定参考价值,需要的朋友可以了解下。

        本文将介绍Java在ICPC快速IO实现方法,下面看看具体代码。

不处理EOF:


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream; 
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
 public static void main(String[] args) {
 InputStream inputStream = System.in;
 OutputStream outputStream = System.out;
 InputReader in = new InputReader(inputStream);
 PrintWriter out = new PrintWriter(outputStream);
 TaskD solver = new TaskD();
 solver.solve(1, in, out);
 out.close();
 } 
 static class TaskD {
 public void solve(int testNumber, InputReader in, PrintWriter out) { 
 }
 } 
 static class InputReader {
 public BufferedReader reader;
 public StringTokenizer tokenizer;
 public InputReader(InputStream stream) {
  reader = new BufferedReader(new InputStreamReader(stream), 32768);
  tokenizer = null;
 }
 public String next() {
  while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  try {
   tokenizer = new StringTokenizer(reader.readLine());
  } catch (IOException e) {
   throw new RuntimeException(e);
  }
  }
  return tokenizer.nextToken();
 } 
 public int nextInt() {
  return Integer.parseInt(next());
 } 
 }
}

处理EOF:


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Random;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;
 
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
 public static void main(String[] args) {
 InputStream inputStream = System.in;
 OutputStream outputStream = System.out;
 InputReader in = new InputReader(inputStream);
 PrintWriter out = new PrintWriter(outputStream);
 TaskD solver = new TaskD();
 solver.solve(1, in, out);
 out.close();
 } 
 static class TaskD {
 public void solve(int testNumber, InputReader in, PrintWriter out) {
  while(in.hasNext())
  {
  int a=in.nextInt();
  int b=in.nextInt();
  System.out.println(a+b);
  }
 }
 }
 static class InputReader {
 public BufferedReader reader;
 public StringTokenizer tokenizer;
  public InputReader(InputStream stream) {
  reader = new BufferedReader(new InputStreamReader(stream), 32768);
  tokenizer = null;
 } 
 public boolean hasNext() {
  while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  try {
   String line = reader.readLine();
   if(line == null) return false;
   tokenizer = new StringTokenizer(line);
  } catch (IOException e) {
   throw new RuntimeException(e);
  }
  }
  return true;
 }
 public String next()
 {
  return tokenizer.nextToken();
 }
 public int nextInt() {
  return Integer.parseInt(next());
 }
 }
}

总结

Atas ialah kandungan terperinci Java编程实现在ICPC快速IO的实例详解. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn