Register
|
Login
Home
News
Competitions
Practice
How to
Rankings
Calendar
Arena
CodeFu 2010
CodeFu'10 Highlights
Jazoon'10 Highlights
Schedule
Rules
Prizes
Results
Competitions
»
Main CodeFu Competitons
»
CodeFu 2010
»
Results
CodeFu 2010 Results
Final Round Results
toroman's solution for 200: TrainRoute, written in Java, submitted on 09.05.2010 11:46:12
import java.util.Arrays; import java.util.Comparator; import java.util.Map; import java.util.TreeMap; public class TrainRoute { public String findActualSchedule(String plannedSchedule, String updates) { TreeMap<String, String> map = new TreeMap<String, String>(); String[] p = plannedSchedule.split(" +"); for (int i = 0; i < p.length; i += 2) { map.put(p[i], p[i + 1]); } if (updates.length() > 0) { p = updates.split(" +"); for (int i = 0; i < p.length; i += 2) { map.put(p[i], p[i + 1]); } } String[] res = new String[map.size()]; int j = 0; for (Map.Entry<String, String> e : map.entrySet()) { res[j++] = e.getKey() + " " + e.getValue(); } Arrays.sort(res, new Comparator<String>() { public int compare(String a, String b) { return a.substring(2).compareTo(b.substring(2)); } }); StringBuilder sb = new StringBuilder(); for (String s : res) { sb.append(s); sb.append(' '); } return sb.substring(0, sb.length() - 1); } }