Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <map>
- #include <fstream>
- #include <algorithm>
- // The most magnificent function in this whole program.
- // Prints a RASSE
- void print_rasse()
- {
- std::cout <<
- "=====//==================//===\n"
- " __<<__________________<<__ \n"
- " | ____ ____ ____ ____ ____ | \n"
- " | | | | | | | | | | | | \n"
- " |_|__|_|__|_|__|_|__|_|__|_| \n"
- ".| RASSE |. \n"
- ":|__________________________|: \n"
- "___(o)(o)___(o)(o)___(o)(o)____\n"
- "-------------------------------" << std::endl;
- }
- // Short and sweet main.
- std::vector<std::string> make_vector(std::string a) {
- // Tää ei välttist oo tarpeellinen idk kopioin googlesta
- std::vector<std::string> result;
- result.push_back(a);
- return result;
- }
- std::vector<std::string> split(const std::string& line, const char delimiter, bool ignore_empty = false){
- // Toimii paitsi toi "-löytämisjuttu
- std::vector<std::string> line_info;
- std::string station_info = line;
- std::string new_part = "";
- while(station_info.find(delimiter) != std::string::npos)
- {
- /*if (station_info.find('"') != std::string::npos) {
- // Tää on työn alla <3
- std::string::size_type place1 = 0;
- place1 = station_info.find('"');
- std::string::size_type place2 = 0;
- place2 = station_info.find('"', place1);
- std::string new_part = station_info.substr(place1+1, place2-2);
- station_info = station_info.substr(place2, station_info.size());
- }
- else {*/
- std::string new_part = station_info.substr(0, station_info.find(delimiter));
- station_info = station_info.substr(station_info.find(delimiter)+1, station_info.size());
- if(not (ignore_empty and new_part.empty()))
- {
- line_info.push_back(new_part);
- }
- }
- if(not (ignore_empty and line.empty()))
- {
- line_info.push_back(station_info);
- }
- return line_info;
- }
- std::map<std::string, std::vector<std::string>> read_data() {
- // Tän pitäis toimii kokonaan oikein
- std::map<std::string, std::vector<std::string>> tramway;
- std::string input_file_name = "";
- std::cout << "Give a name for input file: ";
- getline(std::cin, input_file_name);
- std::ifstream input_file(input_file_name);
- if (input_file) {
- std::string s = "";
- while (getline(input_file, s)) {
- std::vector<std::string> parts = split(s, ';');
- if (parts.size() != 2) {
- std::cout << "Error: Invalid format in file.";
- tramway.clear();
- return tramway;
- }
- else {
- std::string line = parts[0];
- std::string station = parts[1];
- if (tramway.find(line) != tramway.end()) {
- if(std::find(tramway.at(line).begin(), tramway.at(line).end(), station) != tramway.at(line).end()) {
- std::cout << "Error: Station/line already exists.";
- tramway.clear();
- return tramway;
- }
- else {
- tramway.at(line).push_back(station);
- }
- }
- else {
- tramway[line] = make_vector(station);
- }
- }
- }
- input_file.close();
- return tramway;
- }
- else {
- std::cout << "Error: File could not be read.";
- return tramway;
- }
- }
- int lines(){
- std::cout << "lines";
- return true;
- }
- int line(){
- std::cout << "line";
- return true;
- }
- int stations(){
- std::cout << "statons";
- return true;
- }
- int station(){
- std::cout << "staton";
- return true;
- }
- int addline(){
- std::cout << "addline";
- return true;
- }
- int addstation(){
- std::cout << "addstation";
- return true;
- }
- int remove(){
- std::cout << "remove";
- return true;
- }
- int main()
- {
- std::map<std::string, std::vector<std::string>> tramway = read_data();
- if (tramway.empty()) {
- return EXIT_FAILURE;
- }
- else {
- while(true){
- std::string input = "";
- std::cout << "tramway> ";
- getline(std::cin, input);
- std::vector<std::string> action = split(input, ' ');
- // Täst eteenpäin mahollisesti vaan täyttä paskaa, lopetin kesken ku älysin et ei välttist fiksuin ratkasu
- if (action[0] == "QUIT" and action.size() == 1) {
- return EXIT_SUCCESS;
- }
- else if (action[0] == "LINES" and action.size() == 1) {
- lines();
- }
- else if (action[0] == "LINE" and action.size() == 1) {
- line();
- }
- else if (action[0] == "STATIONS" and action.size() == 1) {
- stations();
- }
- else if (action[0] == "STATION" and action.size() == 1) {
- station();
- }
- else if (action[0] == "ADDLINE" and action.size() == 1) {
- addline();
- }
- else if (action[0] == "ADDSTATION" and action.size() == 1) {
- addstation();
- }
- else if (action[0] == "REMOVE" and action.size() == 1) {
- remove();
- }
- }
- // Testiprinttausjuttupaskaa tästä eteenpäin, ei kuulu oikeesti lopulliseen
- std::map <std::string, std::vector<std::string> >::const_iterator it;
- for (it = tramway.begin(); it != tramway.end(); ++it)
- {
- std::cout << it->first << std::endl ;
- std::vector<std::string>::const_iterator itVec;
- for (itVec = it->second.begin(); itVec != it->second.end(); ++itVec)
- {
- std::cout << *itVec <<" ";
- }
- std::cout<<std::endl;
- }
- }
- print_rasse();
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement