Saturday, April 19, 2014

TCO 2014 Round 1A Div 1 L1 EllysSortingTrimmer

// TCO 2014 Round 1A Div 1 L1 EllysSortingTrimmer

import java.util.*;
import java.math.*;

//rename the class name before submitting
public class EllysSortingTrimmer {
public static void main(String[] args) {
EllysSortingTrimmer obj = new EllysSortingTrimmer();
System.out.println(
obj.getMin(
"TOPCODER"
, 3
));
}

public String getMin(String S, int L) {
while (true) {
String left = S.substring(0, S.length() - L);
String right = S.substring(S.length() - L);
char[] r = right.toCharArray();
Arrays.sort(r);
right = new String(r);
if (left.length() == 0)
return right;
else
S = left + right.substring(0, right.length() - 1);
}
}
}

No comments:

Post a Comment