首頁 > Java > java教程 > 主體

Java程式實作在ICPC快速IO的實例詳解

黄舟
發布: 2017-09-11 10:27:42
原創
1383 人瀏覽過

這篇文章主要介紹了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());
 }
 }
}
登入後複製

##總結

以上是Java程式實作在ICPC快速IO的實例詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板