diff --git a/src/de/sunbits/codeeval/packageproblem/Main.java b/src/de/sunbits/codeeval/packageproblem/Main.java index b018b3d..5836fd6 100644 --- a/src/de/sunbits/codeeval/packageproblem/Main.java +++ b/src/de/sunbits/codeeval/packageproblem/Main.java @@ -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. @@ -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 { @@ -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; @@ -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]); @@ -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; } diff --git a/src/de/sunbits/codeeval/packageproblem/results.txt b/src/de/sunbits/codeeval/packageproblem/results.txt index f25b5fb..a8bd0f1 100644 --- a/src/de/sunbits/codeeval/packageproblem/results.txt +++ b/src/de/sunbits/codeeval/packageproblem/results.txt @@ -1 +1,2 @@ -1 Java Jul 14, 2015 Solved 100 771 6164480 yes 81.444 Share on LinkedIn DELETE \ No newline at end of file +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 \ No newline at end of file