Refactored all solutions

This commit is contained in:
rshaghoulian
2017-04-05 18:42:35 -05:00
parent 5f4c2f4a78
commit decc8e791e
135 changed files with 848 additions and 849 deletions
@@ -13,30 +13,31 @@ import java.util.ArrayList;
// - used StringBuffer to do 1 output to console instead of multiple outputs
public class Solution {
public static void main(String[] args) throws IOException {
public static void main(String [] args) throws IOException {
final int maxValue = 100;
HashMap<Integer, ArrayList<String>> map = new HashMap<>();
/* Create HashMap with empty "buckets" to put Strings into */
HashMap<Integer, ArrayList<String>> map = new HashMap<>(maxValue);
for (int i = 0; i < maxValue; i++) {
map.put(i, new ArrayList<String>());
}
/* Save input */
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
for (int i = 0; i < n; i++) {
String[] pair = br.readLine().split(" ");
int key = Integer.parseInt(pair[0]);
String value = (i < n/2) ? "-" : pair[1];
String [] pair = br.readLine().split(" ");
int key = Integer.parseInt(pair[0]);
String value = (i < n/2) ? "-" : pair[1];
ArrayList<String> list = map.get(key);
if (list == null) {
list = new ArrayList<String>();
map.put(key, list);
}
list.add(value);
}
br.close();
/* Print output */
StringBuffer sb = new StringBuffer();
for (int i = 0; i < map.size(); i++) {
for (int i = 0; i < maxValue; i++) {
ArrayList<String> values = map.get(i);
for (String str : values) {
sb.append(str + " ");