diff options
author | Haidong Ji | 2018-08-07 15:03:52 -0500 |
---|---|---|
committer | Haidong Ji | 2018-08-07 15:03:52 -0500 |
commit | 24b8ab29aad9159d1eb285f72a0557c2daea4b11 (patch) | |
tree | 222d5f1a5c6904f9bf50cc9f915d137fcbd2b2a6 | |
parent | b1a00e657e9534ae243d4fa1373d54aaff2847dc (diff) |
Made FastScanner a static class member instead of an independent class.
Appear to consume a bit of more memory.
-rw-r--r-- | AlgoDesignAndTechniqueEdxJava/sources/MaxPairProduct.java | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/AlgoDesignAndTechniqueEdxJava/sources/MaxPairProduct.java b/AlgoDesignAndTechniqueEdxJava/sources/MaxPairProduct.java index dbe4ee6..fc7028c 100644 --- a/AlgoDesignAndTechniqueEdxJava/sources/MaxPairProduct.java +++ b/AlgoDesignAndTechniqueEdxJava/sources/MaxPairProduct.java @@ -16,13 +16,13 @@ public class MaxPairProduct { public static void main(String[] args) { FastScanner s = new FastScanner(System.in); - + int n = s.nextInt(); MaxPairProduct mpp = new MaxPairProduct(n); - for (int i = 0; i<n; i++) { + for (int i = 0; i < n; i++) { mpp.newNumber(s.nextInt()); } - + System.out.println(mpp.getProduct()); } @@ -55,32 +55,31 @@ public class MaxPairProduct { return (long) biggest * (long) bigger; } -} - -final class FastScanner { - BufferedReader br; - StringTokenizer st; - - FastScanner(InputStream stream) { - try { - br = new BufferedReader(new InputStreamReader(stream)); - } catch (Exception e) { - e.printStackTrace(); - } - } + static class FastScanner { + BufferedReader br; + StringTokenizer st; - String next() { - while (st == null || !st.hasMoreTokens()) { + FastScanner(InputStream stream) { try { - st = new StringTokenizer(br.readLine()); - } catch (IOException e) { + br = new BufferedReader(new InputStreamReader(stream)); + } catch (Exception e) { e.printStackTrace(); } } - return st.nextToken(); - } - - int nextInt() { - return Integer.parseInt(next()); + + 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()); + } } -}
\ No newline at end of file +} |