JAVA   22

Whitelist.java

Guest on 12th January 2022 05:18:38 PM

  1. /*************************************************************************
  2.  *  Compilation:  javac Whitelist.java
  3.  *  Execution:    java Whitelist whitelist.txt < data.txt
  4.  *  Dependencies: StaticSetOfInts.java In.java StdOut.java
  5.  *  Data files:  /tinyW.txt
  6.  *                /11model/tinyT.txt
  7.  *                /11model/largeW.txt
  8.  *                /11model/largeT.txt
  9.  *
  10.  *  Whitelist filter.
  11.  *
  12.  *
  13.  *  % java Whitelist tinyW.txt < tinyT.txt
  14.  *  50
  15.  *  99
  16.  *  13
  17.  *
  18.  *  % java Whitelist largeW.txt < largeT.txt | more
  19.  *  499569
  20.  *  984875
  21.  *  295754
  22.  *  207807
  23.  *  140925
  24.  *  161828
  25.  *  [367,966 total values]
  26.  *
  27.  *************************************************************************/
  28.  
  29. public class Whitelist {
  30.     public static void main(String[] args) {
  31.         int[] w = In.readInts(args[0]);
  32.         StaticSETofInts set = new StaticSETofInts(w);
  33.  
  34.         // Read key, print if not in whitelist.
  35.         while (!StdIn.isEmpty()) {
  36.             int key = StdIn.readInt();
  37.             if (!set.contains(key))
  38.                 StdOut.println(key);
  39.         }
  40.     }
  41. }

Raw Paste


Login or Register to edit or fork this paste. It's free.