Makefile: dodano symbole do kompilacji
main.cpp: Działa troszkę bardziej
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
build:
|
||||
g++ -Iinclude main.cpp
|
||||
g++ -g -Iinclude main.cpp
|
||||
|
||||
clean:
|
||||
rm -f a.out
|
||||
|
||||
@@ -31,12 +31,14 @@ uruchomienie programu bez parametrów powoduje wypisanie krótkiej instrukcji
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include "include/cxxopts.hpp"
|
||||
#include "include/types.hpp"
|
||||
#include <algorithm>
|
||||
#include <limits.h>
|
||||
#include <queue>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
double nieskończoność=std::numeric_limits<double>::max();
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -48,23 +50,25 @@ cxxopts::Options options("Kurier", "Program rozwiązujący problem kuriera");
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
std::vector<std::vector<double>> macierzOdległości;
|
||||
|
||||
|
||||
|
||||
|
||||
typedef std::map<std::string, std::map<std::string, double>> 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<string>();
|
||||
parseInput(plikWejsciowy);
|
||||
dijkstruj(mapaOdległości);
|
||||
plikWyjsciowy = result["output"].as<string>();
|
||||
} 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user