Advertisement
Guest User

Bus stops - 1

a guest
Aug 18th, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <set>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. //функция, проверяющая, есть ли в векторе определенная строка
  11.  
  12. bool FindVector (const vector <string>& a, const string& b) {
  13. for (const auto& m : a) {
  14. if (m == b) {
  15. return true;
  16. }
  17.  
  18. }
  19. return false;
  20. }
  21.  
  22.  
  23. int main () {
  24. map <string, vector<string>> bus_to_stops;
  25. map <string, vector<string>> stop_to_buses;
  26. int Q;
  27. cin >> Q;
  28. for (int i = 0; i < Q; ++i) {
  29. string code;
  30. cin >> code;
  31.  
  32. if (code == "NEW_BUS") {
  33. string bus;
  34. int stop_count;
  35. cin >> bus >> stop_count;
  36. for (int w = 0; w < stop_count; ++w) {
  37. string stop;
  38. cin >> stop;
  39. bus_to_stops[bus].push_back(stop);
  40. stop_to_buses[stop].push_back(bus);
  41. }
  42. }
  43.  
  44. else if (code == "BUSES_FOR_STOP") {
  45. string stop;
  46. int th = 0;
  47. cin >> stop;
  48. for (const auto& x : bus_to_stops) {
  49. if (FindVector(x.second, stop) == 1) {
  50. cout << x.first << " ";
  51. th++;
  52. }
  53. }
  54. if (th == 0) {
  55. cout << "No stop";
  56. }
  57. cout << endl;
  58. }
  59. else if (code == "STOPS_FOR_BUS") {
  60. string bus;
  61. cin >> bus;
  62. if (bus_to_stops[bus].empty() == 1) {
  63. cout << "No bus" << endl;
  64. bus_to_stops.erase(bus);
  65. }
  66. else {
  67. for (const auto &t : bus_to_stops[bus]) {
  68. cout << "Stop " << t << ": ";
  69. if (stop_to_buses[t].size() == 1)
  70. cout << "no interchange" << endl;
  71. else {
  72. for (const auto &u : stop_to_buses[t]) {
  73. if (u != bus)
  74. cout << u << " ";
  75. }
  76. cout << endl;
  77. }
  78. }
  79. }
  80.  
  81. }
  82. else if (code == "ALL_BUSES") {
  83. if (bus_to_stops.empty() == 1)
  84. cout << "No buses" << endl;
  85. else {
  86. for (const auto& x : bus_to_stops) {
  87. cout << "Bus " << x.first << ": ";
  88. for (const auto& r : x.second) {
  89. cout << r << " ";
  90. }
  91. cout << endl;
  92. }
  93. }
  94.  
  95. }
  96. }
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement