Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <map>
  5. #include <fstream>
  6. #include <algorithm>
  7.  
  8. // The most magnificent function in this whole program.
  9. // Prints a RASSE
  10. void print_rasse()
  11. {
  12. std::cout <<
  13. "=====//==================//===\n"
  14. " __<<__________________<<__ \n"
  15. " | ____ ____ ____ ____ ____ | \n"
  16. " | | | | | | | | | | | | \n"
  17. " |_|__|_|__|_|__|_|__|_|__|_| \n"
  18. ".| RASSE |. \n"
  19. ":|__________________________|: \n"
  20. "___(o)(o)___(o)(o)___(o)(o)____\n"
  21. "-------------------------------" << std::endl;
  22. }
  23.  
  24. // Short and sweet main.
  25.  
  26. std::vector<std::string> make_vector(std::string a) {
  27. // Tää ei välttist oo tarpeellinen idk kopioin googlesta
  28. std::vector<std::string> result;
  29. result.push_back(a);
  30. return result;
  31. }
  32.  
  33. std::vector<std::string> split(const std::string& line, const char delimiter, bool ignore_empty = false){
  34. // Toimii paitsi toi "-löytämisjuttu
  35. std::vector<std::string> line_info;
  36. std::string station_info = line;
  37. std::string new_part = "";
  38.  
  39. while(station_info.find(delimiter) != std::string::npos)
  40. {
  41. /*if (station_info.find('"') != std::string::npos) {
  42. // Tää on työn alla <3
  43. std::string::size_type place1 = 0;
  44. place1 = station_info.find('"');
  45. std::string::size_type place2 = 0;
  46. place2 = station_info.find('"', place1);
  47. std::string new_part = station_info.substr(place1+1, place2-2);
  48. station_info = station_info.substr(place2, station_info.size());
  49. }
  50. else {*/
  51. std::string new_part = station_info.substr(0, station_info.find(delimiter));
  52. station_info = station_info.substr(station_info.find(delimiter)+1, station_info.size());
  53.  
  54. if(not (ignore_empty and new_part.empty()))
  55. {
  56. line_info.push_back(new_part);
  57. }
  58. }
  59. if(not (ignore_empty and line.empty()))
  60. {
  61. line_info.push_back(station_info);
  62. }
  63. return line_info;
  64. }
  65.  
  66. std::map<std::string, std::vector<std::string>> read_data() {
  67. // Tän pitäis toimii kokonaan oikein
  68. std::map<std::string, std::vector<std::string>> tramway;
  69. std::string input_file_name = "";
  70. std::cout << "Give a name for input file: ";
  71. getline(std::cin, input_file_name);
  72.  
  73. std::ifstream input_file(input_file_name);
  74. if (input_file) {
  75. std::string s = "";
  76. while (getline(input_file, s)) {
  77. std::vector<std::string> parts = split(s, ';');
  78. if (parts.size() != 2) {
  79. std::cout << "Error: Invalid format in file.";
  80. tramway.clear();
  81. return tramway;
  82. }
  83. else {
  84. std::string line = parts[0];
  85. std::string station = parts[1];
  86. if (tramway.find(line) != tramway.end()) {
  87. if(std::find(tramway.at(line).begin(), tramway.at(line).end(), station) != tramway.at(line).end()) {
  88. std::cout << "Error: Station/line already exists.";
  89. tramway.clear();
  90. return tramway;
  91. }
  92. else {
  93. tramway.at(line).push_back(station);
  94. }
  95. }
  96. else {
  97. tramway[line] = make_vector(station);
  98. }
  99. }
  100. }
  101. input_file.close();
  102. return tramway;
  103. }
  104. else {
  105. std::cout << "Error: File could not be read.";
  106. return tramway;
  107. }
  108.  
  109. }
  110.  
  111. int lines(){
  112. std::cout << "lines";
  113. return true;
  114. }
  115.  
  116. int line(){
  117. std::cout << "line";
  118. return true;
  119.  
  120. }
  121.  
  122. int stations(){
  123. std::cout << "statons";
  124. return true;
  125. }
  126.  
  127. int station(){
  128. std::cout << "staton";
  129. return true;
  130. }
  131.  
  132. int addline(){
  133. std::cout << "addline";
  134. return true;
  135. }
  136.  
  137. int addstation(){
  138. std::cout << "addstation";
  139. return true;
  140. }
  141.  
  142. int remove(){
  143. std::cout << "remove";
  144. return true;
  145. }
  146.  
  147. int main()
  148. {
  149. std::map<std::string, std::vector<std::string>> tramway = read_data();
  150.  
  151. if (tramway.empty()) {
  152. return EXIT_FAILURE;
  153. }
  154.  
  155. else {
  156. while(true){
  157. std::string input = "";
  158. std::cout << "tramway> ";
  159. getline(std::cin, input);
  160. std::vector<std::string> action = split(input, ' ');
  161.  
  162. // Täst eteenpäin mahollisesti vaan täyttä paskaa, lopetin kesken ku älysin et ei välttist fiksuin ratkasu
  163.  
  164. if (action[0] == "QUIT" and action.size() == 1) {
  165. return EXIT_SUCCESS;
  166. }
  167. else if (action[0] == "LINES" and action.size() == 1) {
  168. lines();
  169. }
  170. else if (action[0] == "LINE" and action.size() == 1) {
  171. line();
  172. }
  173. else if (action[0] == "STATIONS" and action.size() == 1) {
  174. stations();
  175. }
  176. else if (action[0] == "STATION" and action.size() == 1) {
  177. station();
  178. }
  179. else if (action[0] == "ADDLINE" and action.size() == 1) {
  180. addline();
  181. }
  182. else if (action[0] == "ADDSTATION" and action.size() == 1) {
  183. addstation();
  184. }
  185. else if (action[0] == "REMOVE" and action.size() == 1) {
  186. remove();
  187. }
  188. }
  189.  
  190. // Testiprinttausjuttupaskaa tästä eteenpäin, ei kuulu oikeesti lopulliseen
  191.  
  192. std::map <std::string, std::vector<std::string> >::const_iterator it;
  193.  
  194. for (it = tramway.begin(); it != tramway.end(); ++it)
  195. {
  196. std::cout << it->first << std::endl ;
  197.  
  198. std::vector<std::string>::const_iterator itVec;
  199. for (itVec = it->second.begin(); itVec != it->second.end(); ++itVec)
  200. {
  201. std::cout << *itVec <<" ";
  202. }
  203. std::cout<<std::endl;
  204. }
  205. }
  206.  
  207. print_rasse();
  208. return EXIT_SUCCESS;
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement