public int minimumPrice(long[] dread, int[] price) {
   int n = dread.length;
   int m = n << 1;
   long[] maximum = new long[m + 1];
   Arrays.fill(maximum, 0);
   for (int i = 0; i < n; ++i) {
     long[] new_maximum = new long[m + 1];
     Arrays.fill(new_maximum, -1);
     for (int j = 0; j <= m; ++j) {
       if (maximum[j] != -1) {
         if (maximum[j] >= dread[i]) {
           new_maximum[j] = Math.max(new_maximum[j], maximum[j]);
         }
         if (j + price[i] <= m) {
           new_maximum[j + price[i]] = Math.max(new_maximum[j + price[i]], maximum[j] + dread[i]);
         }
       }
     }
     maximum = new_maximum;
   }
   int answer = 0;
   while (maximum[answer] == -1) {
     answer++;
   }
   return answer;
 }
Exemple #2
1
 public BigInteger count(int n) {
   BigInteger[] prev = new BigInteger[k];
   Arrays.fill(prev, BigInteger.ZERO);
   prev[s] = BigInteger.ONE;
   while (n-- > 0) {
     BigInteger[] next = new BigInteger[k];
     Arrays.fill(next, BigInteger.ZERO);
     for (int i = 0; i < k; ++i) {
       if (prev[i].signum() <= 0) {
         continue;
       }
       for (int j = 0; j < z; ++j) {
         if (e[j][i] < 0) {
           continue;
         }
         next[e[j][i]] = next[e[j][i]].add(prev[i]);
       }
     }
     prev = next;
   }
   BigInteger ans = BigInteger.ZERO;
   for (int term : t) {
     ans = ans.add(prev[term]);
   }
   return ans;
 }
  public int count(int b1, int q1, int n1, int b2, int q2, int n2) {
    if (b2 == 0 || q2 <= 1) {
      int tb = b1;
      int tq = q1;
      int tn = n1;
      b1 = b2;
      q1 = q2;
      n1 = n2;
      b2 = tb;
      q2 = tq;
      n2 = tn;
    }

    if (b1 == 0 || q1 <= 1) {
      HashSet<Integer> set = new HashSet<Integer>();
      set.add(b1);
      if (n1 > 1) {
        set.add(b1 * q1);
      }

      long curr = b2;
      for (int i = 0; i < n2; i++) {
        set.add((int) curr);
        curr *= q2;
        if (curr > 500000000) {
          return (n2 - i - 1) + set.size();
        }
      }

      return set.size();
    } else {
      HashSet<String> set = new HashSet<String>();

      int factors[] = findFactors(b1, q1, b2, q2);
      int repb1[] = decompose(b1, factors);
      int repb2[] = decompose(b2, factors);
      int repq1[] = decompose(q1, factors);
      int repq2[] = decompose(q2, factors);

      for (int i = 0; i < n1; i++) {
        set.add(Arrays.toString(repb1));
        for (int j = 0; j < repb1.length; j++) {
          repb1[j] += repq1[j];
        }
      }

      for (int i = 0; i < n2; i++) {
        set.add(Arrays.toString(repb2));
        for (int j = 0; j < repb2.length; j++) {
          repb2[j] += repq2[j];
        }
      }

      return set.size();
    }
  }
Exemple #4
1
 static List<Answer> solve(int[] numbers) {
   int n = numbers.length;
   Element[] a = new Element[n];
   for (int i = 0; i < n; i++) {
     a[i] = new Element(numbers[i], i);
   }
   int id = -1;
   for (int i = 0; i < n; i++) {
     if (luckies.contains(a[i].x)) {
       id = i;
       break;
     }
   }
   Element[] b = a.clone();
   Arrays.sort(b);
   if (Arrays.equals(a, b)) {
     return new ArrayList<Answer>();
   }
   if (id == -1) {
     return null;
   }
   boolean[] did = new boolean[n];
   for (int i = 0; i < n; i++) {
     if (a[i] == b[i]) {
       did[i] = true;
     }
   }
   List<Answer> ans = new ArrayList<Answer>();
   int cur = 0;
   while (cur < n) {
     while (b[id] != a[id]) {
       int newId = b[id].n;
       swap(id, b[id].n, ans, a);
       did[id] = true;
       id = newId;
     }
     while (cur < n && did[cur] || cur == id) {
       cur++;
     }
     if (cur < n) {
       int newId = cur;
       swap(cur, id, ans, a);
       id = newId;
     }
   }
   // for (int i = 1; i < n; i++) {
   // if (a[i].x < a[i - 1].x) {
   // throw new AssertionError();
   // }
   // }
   // if (ans.size() > 2 * n) {
   // throw new AssertionError();
   // }
   return ans;
 }
 public void setSwingDataCollection(Collection<ICFSecurityISOCountryObj> value) {
   final String S_ProcName = "setSwingDataCollection";
   swingDataCollection = value;
   if (swingDataCollection == null) {
     arrayOfISOCountry = new ICFSecurityISOCountryObj[0];
   } else {
     int len = value.size();
     arrayOfISOCountry = new ICFSecurityISOCountryObj[len];
     Iterator<ICFSecurityISOCountryObj> iter = swingDataCollection.iterator();
     int idx = 0;
     while (iter.hasNext() && (idx < len)) {
       arrayOfISOCountry[idx++] = iter.next();
     }
     if (idx < len) {
       throw CFLib.getDefaultExceptionFactory()
           .newRuntimeException(
               getClass(),
               S_ProcName,
               "Collection iterator did not fully populate the array copy");
     }
     if (iter.hasNext()) {
       throw CFLib.getDefaultExceptionFactory()
           .newRuntimeException(
               getClass(),
               S_ProcName,
               "Collection iterator had left over items when done populating array copy");
     }
     Arrays.sort(arrayOfISOCountry, compareISOCountryByQualName);
   }
   PickerTableModel tblDataModel = getDataModel();
   if (tblDataModel != null) {
     tblDataModel.fireTableDataChanged();
   }
 }
Exemple #6
0
 public long numWays(int width, int height, String[] bad) {
   dpTable = new long[width][height];
   final boolean valid[][] = new boolean[width][height];
   for (int i = 0; i < width; ++i) {
     Arrays.fill(dpTable[i], -1l);
     Arrays.fill(valid[i], true);
   }
   dpTable[0][0] = 0l;
   for (int i = 0; i < width; ++i) {
     for (int j = 0; j < height; ++j) {}
   }
   return 0l;
 }
Exemple #7
0
  public static void main(String[] args) {
    // Generics, varargs & boxing working together:
    List<Integer> li = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
    Integer result = reduce(li, new IntegerAdder());
    print(result);

    result = reduce(li, new IntegerSubtracter());
    print(result);

    print(filter(li, new GreaterThan<Integer>(4)));

    print(forEach(li, new MultiplyingIntegerCollector()).result());

    print(
        forEach(filter(li, new GreaterThan<Integer>(4)), new MultiplyingIntegerCollector())
            .result());

    MathContext mc = new MathContext(7);
    List<BigDecimal> lbd =
        Arrays.asList(
            new BigDecimal(1.1, mc),
            new BigDecimal(2.2, mc),
            new BigDecimal(3.3, mc),
            new BigDecimal(4.4, mc));
    BigDecimal rbd = reduce(lbd, new BigDecimalAdder());
    print(rbd);

    print(filter(lbd, new GreaterThan<BigDecimal>(new BigDecimal(3))));

    // Use the prime-generation facility of BigInteger:
    List<BigInteger> lbi = new ArrayList<BigInteger>();
    BigInteger bi = BigInteger.valueOf(11);
    for (int i = 0; i < 11; i++) {
      lbi.add(bi);
      bi = bi.nextProbablePrime();
    }
    print(lbi);

    BigInteger rbi = reduce(lbi, new BigIntegerAdder());
    print(rbi);
    // The sum of this list of primes is also prime:
    print(rbi.isProbablePrime(5));

    List<AtomicLong> lal =
        Arrays.asList(
            new AtomicLong(11), new AtomicLong(47), new AtomicLong(74), new AtomicLong(133));
    AtomicLong ral = reduce(lal, new AtomicLongAdder());
    print(ral);

    print(transform(lbd, new BigDecimalUlp()));
  }
 public int count(
     String[] s1000,
     String[] s100,
     String[] s10,
     String[] s1,
     String[] t1000,
     String[] t100,
     String[] t10,
     String[] t1) {
   String S1000 = concate(s1000);
   String S100 = concate(s100);
   String S10 = concate(s10);
   String S1 = concate(s1);
   String T1000 = concate(t1000);
   String T100 = concate(t100);
   String T10 = concate(t10);
   String T1 = concate(t1);
   int n = S1000.length();
   Interval[] intervals = new Interval[n];
   for (int i = 0; i < n; ++i) {
     intervals[i] =
         new Interval(
             Integer.parseInt(
                 S1000.substring(i, i + 1) + S100.charAt(i) + S10.charAt(i) + S1.charAt(i)),
             Integer.parseInt(
                 T1000.substring(i, i + 1) + T100.charAt(i) + T10.charAt(i) + T1.charAt(i)));
   }
   Arrays.sort(intervals);
   int leftmost = Integer.MAX_VALUE;
   int rightmost = Integer.MIN_VALUE;
   for (int i = 0; i < n; ++i) {
     leftmost = Math.min(leftmost, intervals[i].b);
     rightmost = Math.max(rightmost, intervals[i].a);
   }
   int answer = 0;
   for (int i = 0; i < n; ++i) {
     int total = 0;
     int now = leftmost;
     int j = 0;
     while (true) {
       if (intervals[i].a <= now) {
         now = Math.max(now, intervals[i].b);
       }
       if (now >= rightmost) {
         break;
       }
       int best = now;
       while (j < n && intervals[j].a <= now) {
         best = Math.max(best, intervals[j++].b);
       }
       if (best <= now) {
         return -1;
       }
       total++;
       now = best;
     }
     answer += total;
   }
   return answer;
 }
Exemple #9
0
 public void run() {
   try {
     int n = reader.nextInt();
     int[] a = new int[n];
     for (int i = 0; i < n; ++i) {
       a[i] = reader.nextInt();
     }
     BigInteger[] ways = new BigInteger[4];
     ways[0] = ways[1] = BigInteger.ONE;
     ways[2] = ways[3] = BigInteger.ZERO;
     for (int i = 0; i < n; ++i) {
       BigInteger[] newWays = new BigInteger[4];
       Arrays.fill(newWays, BigInteger.ZERO);
       for (int mask = 0; mask < 4; ++mask) {
         for (int now = 0; now < 2; ++now) {
           int newMask = mask << 1 | now;
           if (Integer.bitCount(newMask) == a[i]) {
             newWays[newMask & 3] = newWays[newMask & 3].add(ways[mask]);
           }
         }
       }
       ways = newWays;
     }
     BigInteger answer = ways[0].add(ways[2]);
     writer.println(answer);
   } catch (IOException ex) {
   }
   writer.close();
 }
 public void loadData(boolean forceReload) {
   ICFFreeSwitchSchemaObj schemaObj = swingSchema.getSchema();
   if ((containingCluster == null) || forceReload) {
     CFSecurityAuthorization auth = schemaObj.getAuthorization();
     long containingClusterId = auth.getSecClusterId();
     containingCluster = schemaObj.getClusterTableObj().readClusterByIdIdx(containingClusterId);
   }
   if ((listOfTenant == null) || forceReload) {
     arrayOfTenant = null;
     listOfTenant =
         schemaObj
             .getTenantTableObj()
             .readTenantByClusterIdx(containingCluster.getRequiredId(), swingIsInitializing);
     if (listOfTenant != null) {
       Object objArray[] = listOfTenant.toArray();
       if (objArray != null) {
         int len = objArray.length;
         arrayOfTenant = new ICFSecurityTenantObj[len];
         for (int i = 0; i < len; i++) {
           arrayOfTenant[i] = (ICFSecurityTenantObj) objArray[i];
         }
         Arrays.sort(arrayOfTenant, compareTenantByQualName);
       }
     }
   }
 }
  private int[] getSelectedRows(int[] selectedRowsNumber, Map[] selectedRowsKeys, Tab tab) {
    if (selectedRowsKeys == null || selectedRowsKeys.length == 0) return new int[0];
    // selectedRowsNumber is the most performant so we use it when possible
    else if (selectedRowsNumber.length == selectedRowsKeys.length) return selectedRowsNumber;
    else {
      // find the rows from the selectedKeys

      // This has a poor performance, but it covers the case when the selected
      // rows are not loaded for the tab, something that can occurs if the user
      // select rows and afterwards reorder the list.
      try {
        int[] s = new int[selectedRowsKeys.length];
        List selectedKeys = Arrays.asList(selectedRowsKeys);
        int end = tab.getTableModel().getTotalSize();
        int x = 0;
        for (int i = 0; i < end; i++) {
          Map key = (Map) tab.getTableModel().getObjectAt(i);
          if (selectedKeys.contains(key)) {
            s[x] = i;
            x++;
          }
        }
        return s;
      } catch (Exception ex) {
        log.warn(XavaResources.getString("fails_selected"), ex);
        throw new XavaException("fails_selected");
      }
    }
  }
 public List<ICFAccTaxObj> readAllTax(boolean forceRead) {
   final String S_ProcName = "readAllTax";
   if ((allTax == null) || forceRead) {
     Map<CFAccTaxPKey, ICFAccTaxObj> map = new HashMap<CFAccTaxPKey, ICFAccTaxObj>();
     allTax = map;
     CFAccTaxBuff[] buffList =
         ((ICFAccSchema) schema.getBackingStore())
             .getTableTax()
             .readAllDerived(schema.getAuthorization());
     CFAccTaxBuff buff;
     ICFAccTaxObj obj;
     for (int idx = 0; idx < buffList.length; idx++) {
       buff = buffList[idx];
       obj = newInstance();
       obj.setPKey(((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newPKey());
       obj.setBuff(buff);
       ICFAccTaxObj realized = (ICFAccTaxObj) obj.realize();
     }
   }
   Comparator<ICFAccTaxObj> cmp =
       new Comparator<ICFAccTaxObj>() {
         public int compare(ICFAccTaxObj lhs, ICFAccTaxObj rhs) {
           if (lhs == null) {
             if (rhs == null) {
               return (0);
             } else {
               return (-1);
             }
           } else if (rhs == null) {
             return (1);
           } else {
             CFAccTaxPKey lhsPKey = lhs.getPKey();
             CFAccTaxPKey rhsPKey = rhs.getPKey();
             int ret = lhsPKey.compareTo(rhsPKey);
             return (ret);
           }
         }
       };
   int len = allTax.size();
   ICFAccTaxObj arr[] = new ICFAccTaxObj[len];
   Iterator<ICFAccTaxObj> valIter = allTax.values().iterator();
   int idx = 0;
   while ((idx < len) && valIter.hasNext()) {
     arr[idx++] = valIter.next();
   }
   if (idx < len) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentUnderflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   } else if (valIter.hasNext()) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentOverflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   }
   Arrays.sort(arr, cmp);
   ArrayList<ICFAccTaxObj> arrayList = new ArrayList<ICFAccTaxObj>(len);
   for (idx = 0; idx < len; idx++) {
     arrayList.add(arr[idx]);
   }
   List<ICFAccTaxObj> sortedList = arrayList;
   return (sortedList);
 }
 public static void main(String[] args) {
   Scanner inp = new Scanner(System.in);
   int n = inp.nextInt();
   String[] store = new String[n];
   for (int i = 0; i < n; i++) store[i] = inp.next();
   int[] cnt = new int[n];
   Arrays.fill(cnt, 0);
   String str = inp.next();
   for (int j = 0; j < n; j++) {
     int l1 = store[j].length();
     for (int k = 0; k <= (str.length() - l1); k++) {
       if (str.substring(k, k + l1).equals(store[j])) {
         cnt[j] = cnt[j] + 1;
       }
     }
   }
   int y = 0;
   for (int m = 0; m < n; m++) {
     y = Math.max(y, cnt[m]);
   }
   System.out.println(y);
   for (int h = 0; h < n; h++) {
     if (cnt[h] == y) System.out.println(store[h]);
   }
 }
  public static void main(String[] args) throws Exception {

    /*  BufferedReader br=new BufferedReader(new FileReader("input.txt"));
        BufferedWriter out=new BufferedWriter(new FileWriter("output.txt"));
    */
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 2000);
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out), 2000);
    String[] s = br.readLine().split(" ");
    int n = Integer.parseInt(s[0]);
    int q = Integer.parseInt(s[1]);
    int num[] = new int[n + 1];
    int[] m = new int[3 * n + 1]; // size = 2*n+1
    Arrays.fill(num, -1);
    s = br.readLine().split(" ");
    for (int i = 1; i <= n; i++) num[i] = Integer.parseInt(s[i - 1]);
    /// build tree
    maketree(1, 1, n, m, num);

    for (int qq = 1; qq <= q; qq++) {
      s = br.readLine().split(" ");
      int i = Integer.parseInt(s[0]);
      int j = Integer.parseInt(s[1]);
      int ans = query(1, 1, n, m, num, i, j);
      out.write("" + num[ans] + "\n");
      out.flush();
    }
  }
 private long[] parse(String[] as) {
   long ans[] = new long[as.length];
   int index = 0;
   for (String cur : as) ans[index++] = Long.parseLong(cur, 2);
   Arrays.sort(ans);
   return ans;
 }
Exemple #16
0
  void run() {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);

    int n = in.nextInt(), q = in.nextInt();
    int[] v = new int[n], c = new int[n];
    for (int i = 0; i < n; ++i) v[i] = in.nextInt();
    for (int i = 0; i < n; ++i) c[i] = in.nextInt();

    for (int i = 0; i < q; ++i) {
      int a = in.nextInt(), b = in.nextInt();
      long[] dp = new long[n + 1];
      Node[] heap = new Node[2];
      Arrays.fill(dp, -INF);
      for (int j = 0; j < 2; ++j) heap[j] = new Node(-INF, -1);
      for (int j = 0; j < n; ++j) {
        long val = v[j], maxv = val * b;
        int color = c[j];
        maxv = Math.max(dp[color] + val * a, maxv);
        maxv = Math.max(choose(heap, color) + val * b, maxv);
        dp[color] = Math.max(maxv, dp[color]);
        update(heap, dp[color], color);
      }

      long ret = 0;
      for (int j = 1; j <= n; ++j) ret = Math.max(ret, dp[j]);
      out.println(ret);
    }

    out.close();
  }
    @Specialization
    public Object send(RubyBasicObject self, Object[] args, RubyProc block) {
      notDesignedForCompilation();

      final String name = args[0].toString();
      final Object[] sendArgs = Arrays.copyOfRange(args, 1, args.length);
      return self.send(name, block, sendArgs);
    }
Exemple #18
0
 public void Init() {
   fail[0] = 0;
   flag[0] = 0;
   Arrays.fill(ch[0], 0);
   sz = 1;
   for (int i = 0; i < DIC.length(); i++) ID[DIC.charAt(i)] = i;
   CD = DIC.length();
 }
 private static void sort(long[] l1) {
   for (int i = 0; i < l1.length; i++) {
     int q = i + usingRandomGenerator.nextInt(l1.length - i);
     long t = l1[i];
     l1[i] = l1[q];
     l1[q] = t;
   }
   Arrays.sort(l1);
 }
 public int maxCities(int total, int[] d) {
   Arrays.sort(d);
   int n = d.length;
   int answer = 0;
   while (answer < n && total >= d[answer]) {
     total -= d[answer++];
   }
   return answer;
 }
    @Specialization
    public Object methodMissing(RubyBasicObject self, Object[] args, RubyProc block) {
      notDesignedForCompilation();

      CompilerDirectives.transferToInterpreter();

      final RubySymbol name = (RubySymbol) args[0];
      final Object[] sentArgs = Arrays.copyOfRange(args, 1, args.length);
      return methodMissing(self, name, sentArgs, block);
    }
 public static void solve() {
   int cases = scan.nextInt();
   scan.nextLine();
   for (int caze = 1; caze <= cases; caze++) {
     out.print("Case #" + caze + ": ");
     for (int i = 0; i < MAX; i++) Arrays.fill(memo[i], -1);
     str = scan.nextLine().toCharArray();
     out.println(go(0, str.length) ? "YES" : "NO");
   }
 }
Exemple #23
0
 public String[] dealHands(int numPlayers, String deck) {
   int playerId = 0;
   String r[] = new String[numPlayers];
   Arrays.fill(r, "");
   for (int i = 0; i < deck.length() - (deck.length() % numPlayers); i++) {
     r[playerId++] += deck.charAt(i);
     playerId %= numPlayers;
   }
   return r;
 }
    @Specialization
    public Object send(
        RubyBasicObject self,
        Object[] args,
        @SuppressWarnings("unused") UndefinedPlaceholder block) {
      notDesignedForCompilation();

      final String name = args[0].toString();
      final Object[] sendArgs = Arrays.copyOfRange(args, 1, args.length);
      return self.send(name, null, sendArgs);
    }
    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;

      Chessboard that = (Chessboard) o;

      if (!Arrays.equals(board, that.board)) return false;

      return true;
    }
Exemple #26
0
 void solve(int caseNum) {
   int n = in.nextInt();
   BigInteger[] past = new BigInteger[n], d = new BigInteger[n];
   for (int i = 0; i < n; i++) past[i] = new BigInteger(in.next());
   Arrays.sort(past);
   for (int i = 0; i < n; i++) d[i] = past[i].subtract(past[0]);
   for (int i = 2; i < n; i++) d[i] = d[i].gcd(d[i - 1]);
   BigInteger gcd = d[n - 1], mod = past[0].mod(gcd);
   System.out.printf("Case #%d: ", caseNum);
   if (mod.equals(BigInteger.ZERO)) System.out.println(0);
   else System.out.println(gcd.subtract(mod));
 }
  /** {@inheritDoc} */
  @Override
  public Object onReceive(@Nullable Object obj) {
    if (obj instanceof byte[]) {
      X.println(">>> Byte array received over REST: " + Arrays.toString((byte[]) obj));

      BigInteger val = new BigInteger((byte[]) obj);

      X.println(">>> Unpacked a BigInteger from byte array received over REST: " + val);

      return val;
    } else return obj;
  }
Exemple #28
0
  public Main() {
    try {
      BufferedReader in;
      in = new BufferedReader(new InputStreamReader(System.in)); // Used for CCC
      int numLights = Integer.parseInt(in.readLine());
      int[] states = new int[numLights];
      for (int i = 0; i < numLights; i++) {
        states[i] = Integer.parseInt(in.readLine());
      }
      ArrayDeque<Scenario> Q = new ArrayDeque<Scenario>();
      HashMap<String, Integer> dp = new HashMap<String, Integer>();

      int moves = 0;
      Q.addLast(new Scenario(states));
      while (!Q.isEmpty()) {
        int size = Q.size();
        for (int q = 0; q < size; q++) {
          Scenario temp = Q.removeFirst();
          if (isEmpty(temp.states)) {
            System.out.println(moves);
            return;
          } else {
            for (int i = 0; i < temp.states.length; i++) {
              if (temp.states[i] == 0) {
                int[] newArr = Arrays.copyOf(temp.states, temp.states.length);
                newArr[i] = 1;
                newArr = fixArray(newArr);
                String arr = "";
                for (int p = 0; p < newArr.length; p++) arr += newArr[p];
                if (dp.get(arr) == null) {
                  dp.put(arr, moves);
                  Q.addLast(new Scenario(newArr));
                } else {
                  int val = dp.get(arr);
                  if (val != 0 && moves < val) {
                    dp.put(arr, moves);
                    Q.addLast(new Scenario(newArr));
                  }
                }

                // outputArr(newArr);
              }
            }
          }
        }
        moves++;
      }

    } catch (IOException e) {
      System.out.println("IO: General");
    }
  }
  /** {@inheritDoc} */
  @Override
  public Object onSend(Object obj) {
    if (obj instanceof BigInteger) {
      X.println(">>> Creating byte array from BigInteger to send over REST: " + obj);

      byte[] bytes = ((BigInteger) obj).toByteArray();

      X.println(
          ">>> Created byte array from BigInteger to send over REST: " + Arrays.toString(bytes));

      return bytes;
    } else return obj;
  }
Exemple #30
0
 public void Insert(String s) {
   int p = 0;
   for (int i = 0; i < s.length(); i++) {
     int c = ID[s.charAt(i)];
     if (ch[p][c] == 0) {
       Arrays.fill(ch[sz], 0);
       flag[sz] = 0;
       ch[p][c] = sz++;
     }
     p = ch[p][c];
   }
   flag[p] = 1;
 }