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
sweko's solution for 200: TrainRoute, written in C#, submitted on 09.05.2010 13:02:32
using System; using System.Collections.Generic; using System.Text; class TrainRoute { public string findActualSchedule (string plannedSchedule, string updates) { List<Station> stations = new List<Station>(); string[] planned = plannedSchedule.Split(' '); for (int i = 0; i < (planned.Length / 2 ); i++) { Station station = new Station(planned[2*i], planned[2*i+1]); stations.Add(station); } string[] update = updates.Split(' '); for (int i = 0; i < (update.Length / 2 ); i++) { Station newStat = new Station(update[2*i], update[2*i+1]); Station oldStat = stations.Find(delegate (Station station) { return (station.StationID == newStat.StationID);}); oldStat.Time = newStat.Time; } StringBuilder sb = new StringBuilder(); foreach (Station station in stations) { sb.Append(station); sb.Append(" "); } sb.Remove(sb.Length-1,1); return sb.ToString(); } } class Station { public string StationID; public int Time; public Station(string station) { string[] tokens = station.Split(' ',':'); StationID = tokens[0]; Time = int.Parse(tokens[1])*60+int.Parse(tokens[2]); } public Station(string stationID, string time) { StationID = stationID; string[] tokens = time.Split(':'); Time = int.Parse(tokens[0])*60+int.Parse(tokens[1]); } public override string ToString () { int hours = Time / 60; int mins = Time % 60; return string.Format("{0} {1:00}:{2:00}", StationID, hours, mins); } }