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
tomazi's solution for 200: TrainRoute, written in Java, submitted on 09.05.2010 11:45:10
import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class TrainRoute { public String findActualSchedule(String plannedSchedule, String updates) { ArrayList<String> mp = new ArrayList<String>(); Map<String, String> muS = new HashMap<String, String>(); StringTokenizer st = new StringTokenizer(plannedSchedule); while(st.hasMoreTokens()){ String key = st.nextToken(); String time = st.nextToken(); mp.add(key + "-" + time); } st = new StringTokenizer(updates); while(st.hasMoreTokens()){ String key = st.nextToken(); String time = st.nextToken(); muS.put(key, time); } StringBuffer res = new StringBuffer(); for(String time : mp){ String[] ss = time.split("-"); String key = ss[0]; if(muS.containsKey(key)){ res.append(key); res.append(" "); res.append(muS.get(key)); res.append(" "); }else{ res.append(key); res.append(" "); res.append(ss[1]); res.append(" "); } } String r = res.toString(); return r.trim(); } }