From 01e3c049ed2ea9af2666ec9a6886fa7c667145e5 Mon Sep 17 00:00:00 2001 From: ThamerMashni Date: Wed, 4 Aug 2021 09:43:04 +0300 Subject: [PATCH] add files --- RiyadhMetro/Program.cs | 92 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 RiyadhMetro/Program.cs diff --git a/RiyadhMetro/Program.cs b/RiyadhMetro/Program.cs new file mode 100644 index 0000000..9ddf7ae --- /dev/null +++ b/RiyadhMetro/Program.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; + +namespace RiyadhMetro +{ + internal class Program + { + public static List red = new List() + { + "Alwrod", "Salah Aldin", "Alnzha", "Hittin", "Qwrtba", "KSU", "Almalaz", "Diplomatic" + }; + + public static List blue = new List() + { + "Alakeek", "Alyasmin", "Salah Aldin", "Rahmanea", "Motamrat", "Alolya", "Almoroj" + }; + + public static List green = new List() + { + "Nmar", "PNU", "Salah Aldin", "Solaymanea", "Alamal", "Tayba", "Alhazem", "Alzahra" + }; + + public static List startLine; + public static List endLine; + + private static void Main(string[] args) + { + stopsBetweenStations("Red", "Alwrod", "Red", "Diplomatic"); + stopsBetweenStations("Blue", "Alyasmin", "Red", "Alnzha"); + stopsBetweenStations("Red", "Diplomatic", "Green", "Nmar"); + + + } + + public static void stopsBetweenStations(string sLine, string startStation, string eLine, string endStation) + { + bool valid = assignLines(sLine, eLine); + if (!valid) + { + Console.WriteLine("INVALID LINE!"); + return; + } + if (startStation == endStation) { Console.WriteLine("0 stops, You are already at your location."); } + else if (startLine == endLine) + { + Console.WriteLine(Math.Abs(startLine.IndexOf(startStation) - endLine.IndexOf(endStation)) + " stops."); + } + else + { + int counter = 0; + counter = calcIntersection(startLine.IndexOf(startStation), startLine.IndexOf("Salah Aldin")) + + calcIntersection(endLine.IndexOf(endStation), endLine.IndexOf("Salah Aldin")); + Console.WriteLine(counter + " stops."); + } + } + + public static int calcIntersection(int station, int intersection) + { + int stops = 0; + if (station < intersection) + { + for (int i = station; i < intersection; i++) + { + stops++; + } + } + else + { + for (int i = station; i > intersection; i--) + { + stops++; + } + } + return stops; + } + + public static bool assignLines(string sLine, string eLine) + { + if (sLine == "Red") { startLine = red; } + else if (sLine == "Blue") { startLine = blue; } + else if (sLine == "Green") { startLine = green; } + else { return false; } + + if (eLine == "Red") { endLine = red; } + else if (eLine == "Blue") { endLine = blue; } + else if (eLine == "Green") { endLine = green; } + else {return false; } + + return true; + } + } +} \ No newline at end of file