суббота, 12 мая 2012 г.

Java template

Java Template для быстрого чтения-записи

import java.util.*;
import java.io.*;

public class Solution {
 FastScanner in;
 PrintWriter out;

 int N;

 public void solve() throws IOException {
  // solution is here
  N = in.nextInt();
  out.print(N);
 }

 public void run() {
  try {
   // works with files
   in = new FastScanner(new File("input.txt"));
   out = new PrintWriter(new File("output.txt"));

   // works with standart input-output
   //in = new FastScanner(System.in);
   //out = new PrintWriter(System.out);

   solve();

   out.close();
  } catch (IOException e) {
   e.printStackTrace();
  }
 }

 class FastScanner {
  BufferedReader br;
  StringTokenizer st;

  FastScanner(File f) {
   try {
    br = new BufferedReader(new FileReader(f));
   } catch (FileNotFoundException e) {
    e.printStackTrace();
   }
  }

  FastScanner(InputStream f) {
   br = new BufferedReader(new InputStreamReader(f));
  }

  String next() {
   while (st == null || !st.hasMoreTokens()) {
    try {
     st = new StringTokenizer(br.readLine());
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
   return st.nextToken();
  }

  int nextInt() {
   return Integer.parseInt(next());
  }

  long nextLong() {
   return Long.parseLong(next());
  }

  String nextLine() {
   try {
    return br.readLine();
   } catch (IOException e) {
    e.printStackTrace();
   }
   return null;
  }
 }

 public static void main(String[] arg) {
  new Solution().run();
 }
}

Комментариев нет:

Отправить комментарий