Skip to content

Commit

Permalink
package problem optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
fmt-Println-MKO committed Jul 14, 2015
1 parent d85db07 commit f2a123b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/de/sunbits/codeeval/packageproblem/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Pattern;

/**
* Created by matthiaskoch on 09.07.15.
Expand All @@ -34,17 +35,21 @@ public static void main(String[] args) {

private final void solve(final String path) {

final String colon = ":";
final String braces = "\\)\\(";
final String comma = ",";

final Pattern patColon = Pattern.compile(":");
final Pattern patBraces = Pattern.compile("\\)\\(");
final Pattern patComma = Pattern.compile(comma);

final String oBrace = "(";
final String cBrace = ")";

final String empty = "";
final String space = " ";
final String com = ",";
final String dollar = "$";
final String minus = "-";


final int[] emptyIntAr = new int[0];

try {
Expand All @@ -55,16 +60,15 @@ private final void solve(final String path) {

for (String line : lines) {
if (line.length() == 0) {
System.out.println("-");
continue;
}
line = line.replace(space, empty);
String[] packline = line.split(colon);
String[] packline = patColon.split(line, 0);
packageMaxWeight = Integer.valueOf(packline[0]);
if (packageMaxWeight > 100) {
continue;
}
String[] sItems = packline[1].split(braces);
String[] sItems = patBraces.split(packline[1], 0);

int sLength = sItems.length;

Expand All @@ -73,7 +77,7 @@ private final void solve(final String path) {
for (int i = 0; i < sLength; i++) {
String sItem = sItems[i].replace(oBrace, empty);
sItem = sItem.replace(cBrace, empty);
String[] itemData = sItem.split(com);
String[] itemData = patComma.split(sItem, 0);

final float weight = Float.valueOf(itemData[1]);

Expand Down Expand Up @@ -136,7 +140,7 @@ private final void solve(final String path) {
sb.append(i);
j++;
if (j < cPacked) {
sb.append(com);
sb.append(comma);
} else {
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/de/sunbits/codeeval/packageproblem/results.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
1 Java Jul 14, 2015 Solved 100 771 6164480 yes 81.444 Share on LinkedIn DELETE
1 Java Jul 14, 2015 Solved 100 771 6164480 yes 81.444 Share on LinkedIn DELETE
2 Java Jul 14, 2015 Solved 100 811 5632000 yes 82.513 Share on LinkedIn DELETE

0 comments on commit f2a123b

Please sign in to comment.