blob: 0a47ac0c5297a4ce30447e94471d138ccbb507e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
}
|