42 lines
1.0 KiB
Java
42 lines
1.0 KiB
Java
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
public class CalibrationPartTwo {
|
|
public static void main(String[] args) {
|
|
String str = """
|
|
two1nine
|
|
eightwothree
|
|
abcone2threexyz
|
|
xtwone3four
|
|
4nineeightseven2
|
|
zoneight234
|
|
7pqrstsixteen
|
|
""";
|
|
HahsMap<String, String> elements = new HashMap<>();
|
|
elements.put("one", "1");
|
|
elements.put("two", "2");
|
|
elements.put("three", "3");
|
|
elements.put("four", "4");
|
|
elements.put("five", "5");
|
|
elements.put("six", "6");
|
|
elements.put("seven", "7");
|
|
elements.put("eight", "8");
|
|
elements.put("nine", "9");
|
|
|
|
try {
|
|
for (String line : str.split("\n")) {
|
|
for (Map.Entry<String, String> entry : elements.entrySet()) {
|
|
line.replace(entry.getKey(), entry.getValue());
|
|
int first = -1;
|
|
int last = -1;
|
|
}
|
|
for (String c : line.split("")) {
|
|
System.out.println(c);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
// TODO: handle exception
|
|
}
|
|
}
|
|
}
|