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
igorkulev's solution for 200: TrainRoute, written in Java, submitted on 09.05.2010 11:36:06
import java.util.StringTokenizer; public class TrainRoute { /** * @param args */ public static void main(String[] args) { String answer = new TrainRoute().findActualSchedule("A 09:00 B 10:03 C 11:07 D 12:13 E 14:20", "C 11:09 C 11:08 A 09:01"); } public String findActualSchedule(String plannedSchedule, String updates) { int i,j,k; String a,b; int word; int timeh[] = new int[26]; int timem[] = new int[26]; String pom; for (i=0;i<26;i++) { timeh[i] = -1; timem[i] = -1; } StringTokenizer st = new StringTokenizer(plannedSchedule); while (st.hasMoreTokens() == true) { // we read two tokens a = st.nextToken(); b = st.nextToken(); word = (int)a.charAt(0)-(int)('A'); timeh[word] = ((int)b.charAt(0)-(int)('0'))*10+((int)b.charAt(1)-(int)('0')); timem[word] = ((int)b.charAt(3)-(int)('0'))*10+((int)b.charAt(4)-(int)('0')); //System.out.println(word+" "+timeh[word]+" "+timem[word]); } // now we deal with updates st = new StringTokenizer(updates); while (st.hasMoreTokens() == true) { // we read two tokens a = st.nextToken(); b = st.nextToken(); word = (int)a.charAt(0)-(int)('A'); timeh[word] = ((int)b.charAt(0)-(int)('0'))*10+((int)b.charAt(1)-(int)('0')); timem[word] = ((int)b.charAt(3)-(int)('0'))*10+((int)b.charAt(4)-(int)('0')); } String res = ""; st = new StringTokenizer(plannedSchedule); while (st.hasMoreTokens() == true) { // we read two tokens a = st.nextToken(); b = st.nextToken(); word = (int)a.charAt(0)-(int)('A'); res += (char)(word+(int)'A'); res += ' '; pom = Integer.toString(timeh[word]); if (pom.length() == 1) { pom = '0'+pom; } res += pom; res += ':'; pom = Integer.toString(timem[word]); if (pom.length() == 1) { pom = '0'+pom; } res += pom; if (st.hasMoreTokens() == true) { res += ' '; } } return res; } }