knightL

JavaIO

Feb 2nd, 2014
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.05 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Main {
  5.     final static int BUFFERSIZE=1000;
  6.     public static void main(String args[]) throws FileNotFoundException
  7.     {
  8.         InputReader in;
  9.         OutputWriter out;
  10.         try
  11.         {
  12.             in=new InputReader(new FileInputStream(new File("/home/knightl/input")));
  13.             out=new OutputWriter(new FileOutputStream(new File("/home/knightl/output")));
  14.         }
  15.         catch(FileNotFoundException e)
  16.         {
  17.             in = new InputReader(System.in);
  18.             out=new OutputWriter(System.out);          
  19.         }
  20.         int n=in.readInt();
  21.         int arr[]=new int[n];
  22.         for(int i=0;i<n;i++)
  23.             arr[i]=in.readInt();
  24.         for(int i=0;i<n;i++)
  25.             out.printLine(arr[i]);
  26.         out.close();
  27.     }
  28. }
  29.  
  30. class InputReader {
  31.  
  32.     private InputStream stream;
  33.     private byte[] buf = new byte[1024];
  34.     private int curChar;
  35.     private int numChars;
  36.     private SpaceCharFilter filter;
  37.  
  38.     public InputReader(InputStream stream) {
  39.         this.stream = stream;
  40.     }
  41.  
  42.     public int read() {
  43.         if (numChars == -1)
  44.             throw new InputMismatchException();
  45.         if (curChar >= numChars) {
  46.             curChar = 0;
  47.             try {
  48.                 numChars = stream.read(buf);
  49.             } catch (IOException e) {
  50.                 throw new InputMismatchException();
  51.             }
  52.             if (numChars <= 0)
  53.                 return -1;
  54.         }
  55.         return buf[curChar++];
  56.     }
  57.  
  58.     public int readInt() {
  59.         int c = read();
  60.         while (isSpaceChar(c))
  61.             c = read();
  62.         int sgn = 1;
  63.         if (c == '-') {
  64.             sgn = -1;
  65.             c = read();
  66.         }
  67.         int res = 0;
  68.         do {
  69.             if (c < '0' || c > '9')
  70.                 throw new InputMismatchException();
  71.             res *= 10;
  72.             res += c - '0';
  73.             c = read();
  74.         } while (!isSpaceChar(c));
  75.         return res * sgn;
  76.     }
  77.  
  78.     public boolean isSpaceChar(int c) {
  79.         if (filter != null)
  80.             return filter.isSpaceChar(c);
  81.         return isWhitespace(c);
  82.     }
  83.  
  84.     public static boolean isWhitespace(int c) {
  85.         return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  86.     }
  87.  
  88.     public interface SpaceCharFilter {
  89.         public boolean isSpaceChar(int ch);
  90.     }
  91. }
  92.  
  93. class OutputWriter {
  94.     private final OutputStream out;
  95.     private byte[] buf = new byte[1024];
  96.     private byte[] tmp = new byte[1024];
  97.     private int top;
  98.  
  99.     public OutputWriter(OutputStream outputStream) {
  100.         top=0;
  101.         out=outputStream;
  102.     }
  103.  
  104.     public void flush() {
  105.         try {
  106.             out.write(buf,0,top);
  107.             top=0;
  108.         } catch (IOException e) {
  109.             // TODO Auto-generated catch block
  110.             e.printStackTrace();
  111.         }
  112.     }
  113.    
  114.     public void close() {
  115.         flush();
  116.         try {
  117.             out.close();
  118.         } catch (IOException e) {
  119.             e.printStackTrace();
  120.         }
  121.     }
  122.    
  123.     private void add_tmp(int tmp_top)
  124.     {
  125.         for(int j=0;j<tmp_top;j++)
  126.         {
  127.             if(top==buf.length)
  128.                 flush();
  129.             buf[top++]=tmp[j];
  130.         }
  131.     }
  132.    
  133.     public void print(int i) {
  134.         int tmp_top=0;
  135.         if(i==0)
  136.             tmp[tmp_top++]='0';
  137.         else
  138.         {
  139.             boolean sign=i<0;
  140.             if(sign) i=-i;
  141.             while(i!=0)
  142.             {
  143.                 tmp[tmp_top++]=(byte)('0'+i%10);
  144.                 i/=10;
  145.             }
  146.             if(sign)
  147.                 tmp[tmp_top++]='-';
  148.             for(int j=0,k=tmp_top-1;j<k;j++,k--)
  149.             {
  150.                 byte t=tmp[j];
  151.                 tmp[j]=tmp[k];
  152.                 tmp[k]=t;
  153.             }
  154.         }
  155.         add_tmp(tmp_top);
  156.     }
  157.  
  158.     public void printLine(int i) {
  159.         print(i);
  160.         tmp[0]='\n';
  161.         add_tmp(1);
  162.     }
  163.  
  164. }
Advertisement
Add Comment
Please, Sign In to add comment