From 24be70723958f5d8e52e3f613a1a173f06782c49 Mon Sep 17 00:00:00 2001 From: Anzhelika Nikolaieva Date: Mon, 6 Nov 2023 20:33:18 +0000 Subject: [PATCH] Update 'cv7/a_station.c' --- cv7/a_station.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cv7/a_station.c b/cv7/a_station.c index cd1c8b6..60dafa0 100644 --- a/cv7/a_station.c +++ b/cv7/a_station.c @@ -25,12 +25,11 @@ void destroy_station(struct station* station){ } int select_track(struct station* station, const char* target){ - if (isalpha(target[0])) { - char first_letter = tolower(target[0]); - return first_letter - 'a'; - } else { - return 0; + unsigned int hash = 0; + for (int i = 0; target[i]; i++) { + hash = (hash * 31) + target[i]; } + return hash % station->track_count; } void add_target_capacity(struct station* station,const char* target, int capacity){