SHARE
TWEET

Untitled

a guest Oct 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5. #include <map>
  6.  
  7. // The most magnificent function in this whole program.
  8. // Prints a RASSE
  9. void print_rasse()
  10. {
  11.     std::cout <<
  12.                  "=====//==================//===\n"
  13.                  "  __<<__________________<<__   \n"
  14.                  " | ____ ____ ____ ____ ____ |  \n"
  15.                  " | |  | |  | |  | |  | |  | |  \n"
  16.                  " |_|__|_|__|_|__|_|__|_|__|_|  \n"
  17.                  ".|                  RASSE   |. \n"
  18.                  ":|__________________________|: \n"
  19.                  "___(o)(o)___(o)(o)___(o)(o)____\n"
  20.                  "-------------------------------" << std::endl;
  21. }
  22.  
  23. std::vector<std::string> split(const std::string& s, char delimiter = ';'){
  24.     std::vector<std::string> result;
  25.     std::string tmp = s;
  26.  
  27.     while(tmp.find(delimiter) != std::string::npos)
  28.     {
  29.         std::string new_part = tmp.substr(0, tmp.find(delimiter));
  30.         tmp = tmp.substr(tmp.find(delimiter)+1, tmp.size());
  31.         if(not (new_part.empty()))
  32.         {
  33.             result.push_back(new_part);
  34.         }
  35.     }
  36.     if(not tmp.empty())
  37.     {
  38.         result.push_back(tmp);
  39.     }
  40.     return result;
  41. }
  42.  
  43. void routing(std::map<std::string, std::vector<std::string>> route, std::string inp)
  44. {
  45.     std::ifstream file(inp);
  46.     std::string row;
  47.     while(getline(file, row)){
  48.         std::vector<std::string> parts = split(row);
  49.         std::string line = parts.at(0);
  50.         std::string station = parts.at(1);
  51.         if (route.count(line)>0){
  52.             route.at(line).push_back(station);
  53.         }
  54.         else{
  55.             std::vector <std::string> state = {station};
  56.             route.insert({line,state});
  57.         }
  58.     }
  59. }
  60.  
  61. // Short and sweet main.
  62. int main()
  63. {
  64.     std::map<std::string, std::vector<std::string>> route;
  65.     print_rasse();
  66.     std::string inp;
  67.     std::cout << "Give a name for input file: ";
  68.     std::cin >> inp;
  69.     std::ifstream file(inp);
  70.     if ( not file ) {
  71.         std::cout << "Error: File could not be read." << std::endl;
  72.         return EXIT_FAILURE;
  73.     }else{
  74.         std::string row;
  75.         while(getline(file, row)){
  76.             if (row.find(";")==std::string::npos){
  77.                 std::cout << "Error: Invalid format in file." << std::endl;
  78.                 return EXIT_FAILURE;
  79.             }
  80.             else{
  81.                 routing(route, inp);
  82.             }
  83.         }
  84.     }
  85.     return EXIT_SUCCESS;
  86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top