public class Solution {
public List<String> sortRoman(List<String> names) {
List<String> results = new ArrayList<>();
TreeMap<String, String> sorted_map = new TreeMap<>();
for (String name : names) {
String digitsName = name.split(" ")[0] + romanToInt(name.split(" ")[1]);
sorted_map.put(name, digitsName);
}
for (String name : sorted_map.keySet()) {
results.add(name);
}
return results;
}
public int romanToInt(String s) {
char[] sc = new char[s.length()];
sc = s.toCharArray();
int ans = toInt(sc[0]);
for (int i = 1; i < s.length(); i++) {
ans += toInt(sc[i]);
if (toInt(sc[i - 1]) < toInt(sc[i])) {
ans -= 2 * toInt(sc[i - 1]);
}
}
return ans;
}
//toInt
private int toInt (char s) {
switch(s) {
case 'I':return 1;
case 'V':return 5;
case 'X':return 10;
case 'L':return 50;
case 'C':return 100;
case 'D':return 500;
case 'M':return 1000;
}
return 0;
}
}