From f4b109c96a08e2790a153a9113701d9ec4b67043 Mon Sep 17 00:00:00 2001 From: VectorKappa Date: Tue, 21 Feb 2023 01:43:37 +0100 Subject: [PATCH] =?UTF-8?q?Makefile:=20dodano=20symbole=20do=20kompilacji?= =?UTF-8?q?=20main.cpp:=20Dzia=C5=82a=20troszk=C4=99=20bardziej?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Projekt/Makefile | 2 +- Projekt/main.cpp | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Projekt/Makefile b/Projekt/Makefile index c96b27e..44e0571 100644 --- a/Projekt/Makefile +++ b/Projekt/Makefile @@ -1,5 +1,5 @@ build: - g++ -Iinclude main.cpp + g++ -g -Iinclude main.cpp clean: rm -f a.out diff --git a/Projekt/main.cpp b/Projekt/main.cpp index b0bd755..703099a 100644 --- a/Projekt/main.cpp +++ b/Projekt/main.cpp @@ -31,12 +31,14 @@ uruchomienie programu bez parametrów powoduje wypisanie krótkiej instrukcji #include #include #include "include/cxxopts.hpp" +#include "include/types.hpp" #include #include #include #include #include +double nieskończoność=std::numeric_limits::max(); using namespace std; @@ -48,23 +50,25 @@ cxxopts::Options options("Kurier", "Program rozwiązujący problem kuriera"); * * */ - -std::vector> macierzOdległości; - - - - +typedef std::map> mapa; +mapa mapaOdległości; /* * @brief Funkcja czyszcząca stringi z niepotrzebnych znaków */ - - void czyscStringa( string &str, char* znakiDoCzyszczenia ) { for ( unsigned int i = 0; i < strlen(znakiDoCzyszczenia); ++i ) { str.erase( remove(str.begin(), str.end(), znakiDoCzyszczenia[i]), str.end() ); } } + +void dijkstruj(mapa doDijkstrnięcia){ + for(auto miasto : doDijkstrnięcia) + { + // doDijkstrnięcia.rbegin() + } +} + /** * @brief Funkcja parsująca dane wejściowe. * @@ -76,10 +80,22 @@ void czyscStringa( string &str, char* znakiDoCzyszczenia ) { */ void parseInput(string inputFile) { ifstream file(inputFile); - std::string token; + std::string token,miastoA,miastoB,dystans,rodzajRelacji; while(std::getline(file, token, ',')) { - czyscStringa(token, "()"); - std::cout << token << std::endl; + czyscStringa(token, "(:)"); + istringstream tokenstream(token); + tokenstream >> miastoA >> rodzajRelacji >> miastoB >> dystans; + if (rodzajRelacji.compare("-")==0) { + // Jeśli drugie miasto zaczyna się od znaku '-', to znaczy, że jest to droga dwukierunkowa. + // Dodajemy odległość do mapy dla obu kierunków. + mapaOdległości[miastoA][miastoB] = stod(dystans); + mapaOdległości[miastoB][miastoA] = stod(dystans); + } else if (rodzajRelacji.compare("->")==0) { + // Jeśli drugie miasto zaczyna się od znaku '>', to znaczy, że jest to droga jednokierunkowa. + // Dodajemy odległość tylko w jednym kierunku. + mapaOdległości[miastoA][miastoB] = stod(dystans); + mapaOdległości[miastoB][miastoA] = nieskończoność; + } } } /** @@ -109,9 +125,10 @@ int main (int argc, char *argv[]) if (result.count("input") && result.count("output")) { plikWejsciowy = result["input"].as(); parseInput(plikWejsciowy); + dijkstruj(mapaOdległości); plikWyjsciowy = result["output"].as(); } else { - std::cout << std::endl << "Błąd 03 - nie podano wymaganych parametrów" << std::endl << std::endl << std::endl << options.help() << std::endl; + std::cout << std::endl << "Błąd - nie podano wymaganych parametrów" << std::endl << std::endl << std::endl << options.help() << std::endl; exit(3); } if (debug == true) { @@ -123,5 +140,6 @@ int main (int argc, char *argv[]) + exit(0); }