-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b7de1d
commit 77cd8b6
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package de.sunbits.codeeval.interruptedbubblesort; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileReader; | ||
import java.util.regex.Pattern; | ||
|
||
public class Main { | ||
|
||
/** | ||
* @param args the command line arguments | ||
*/ | ||
public static void main(String[] args) { | ||
|
||
final Pattern patRounds = Pattern.compile("\\|"); | ||
final Pattern patSpace = Pattern.compile(" "); | ||
|
||
try { | ||
final BufferedReader inputStream = new BufferedReader(new FileReader(args[0])); | ||
String line; | ||
while ((line = inputStream.readLine()) != null) { | ||
String[] lData = patRounds.split(line, 0); | ||
long rounds = Long.valueOf(lData[1].trim()); | ||
String[] data = patSpace.split(lData[0], 0); | ||
|
||
if (rounds > data.length) { | ||
rounds = data.length; | ||
} | ||
int[] ar = new int[data.length]; | ||
|
||
for (int j = 0; j < rounds; j++) { | ||
for (int i = 0; i < ar.length - 1; i++) { | ||
int v1; | ||
int v2; | ||
if (j == 0 && i == 0) { | ||
v1 = Integer.valueOf(data[i]); | ||
v2 = Integer.valueOf(data[i + 1]); | ||
} else if (j == 0 && i > 0) { | ||
v1 = ar[i]; | ||
v2 = Integer.valueOf(data[i + 1]); | ||
} else { | ||
v1 = ar[i]; | ||
v2 = ar[i + 1]; | ||
} | ||
if (v1 < v2) { | ||
ar[i] = v1; | ||
ar[i + 1] = v2; | ||
} else { | ||
ar[i] = v2; | ||
ar[i + 1] = v1; | ||
} | ||
} | ||
} | ||
for (int i = 0; i < ar.length; i++) { | ||
System.out.print(ar[i] + " "); | ||
} | ||
System.out.println(); | ||
} | ||
} catch (java.io.IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
36 47 78 28 20 79 87 16 8 45 72 69 81 66 60 8 3 86 90 90 | 1 | ||
40 69 52 42 24 16 66 | 2 | ||
54 46 0 34 15 48 47 53 25 18 50 5 21 76 62 48 74 1 43 74 78 29 | 6 | ||
48 51 5 61 18 | 2 | ||
59 68 55 31 73 4 1 25 26 19 60 0 | 1000000000000 |