aboutsummaryrefslogtreecommitdiff
path: root/day9/day9.c
diff options
context:
space:
mode:
Diffstat (limited to 'day9/day9.c')
-rw-r--r--day9/day9.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/day9/day9.c b/day9/day9.c
new file mode 100644
index 0000000..0a47ac0
--- /dev/null
+++ b/day9/day9.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <string.h>
+
+#define MAXCITIES 8
+
+char* cities[MAXCITIES];
+int matrix[MAXCITIES][MAXCITIES];
+int seencity = 0;
+
+int cityindex(char* city) {
+ int i;
+ for(i = 0; i < seencity ; i++)
+ if(strcmp(city, cities[i]) == 0)
+ return i;
+ return -1;
+}
+
+int addcity(char* city) {
+ cities[seencity++] = city;
+ return seencity;
+}
+
+void input(char* from, char* to, int dist) {
+ int f, t;
+ f = cityindex(from);
+ t = cityindex(to);
+ if(f == -1) f = addcity(from);
+ if(t == -1) t = addcity(to);
+ matrix[f][t] = dist;
+ matrix[t][f] = dist;
+}
+
+int main() {
+ char from[20], to[20];
+ int dist, mindist, tourid;
+
+ while(scanf("%s to %s = %d", from, to, &dist) != EOF)
+ input(from, to, dist);
+
+ dist = 0; mindist = 0x7FFFFFFF;
+
+
+ return 0;
+}