Guest User

Untitled

a guest
Dec 8th, 2019
82
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<string>
  3. #include<algorithm>
  4. using namespace std;
  5.  
  6. struct Bus_control
  7. {
  8. int bus_number;
  9. string last_name;
  10. int route_number;
  11. int bus_status;
  12. bool bus_control;
  13. };
  14. int maxi(int a, int b)
  15. {
  16. if (a > b)
  17. return 0;
  18. else
  19. return 1;
  20. }
  21. void sort_struct_bubble(Bus_control* man, int a)
  22. {
  23. for (int i = 0; i < a; i++)
  24. for (int j = 0; j < a - 1; j++)
  25. if (maxi(man[j].bus_number, man[j + 1].bus_number) == 1)
  26. swap(man[j], man[j + 1]);
  27. }
  28. int main()
  29. {
  30. Bus_control* bus = new Bus_control[50];
  31. int i = 0;
  32. int j = 0;
  33. while (true)
  34. {
  35. i++;
  36. cin >> bus[i].bus_number;
  37. if (bus[i].bus_number == 0)
  38. break;
  39. bus[i].bus_control = false;
  40. cin >> bus[i].last_name >> bus[i].route_number;
  41. }
  42. sort_struct_bubble(bus, i);
  43. while (true)
  44. {
  45. j++;
  46. int operation, number;
  47. cin >> operation;
  48. if (operation == 0)
  49. break;
  50. cin >> number;
  51. for (int n = 0; n < i; n++)
  52. {
  53. if (number == bus[n].bus_number&&operation==1)
  54. {
  55. bus[n].bus_control = true;
  56. }
  57. if (number == bus[n].bus_number && operation == 2)
  58. {
  59. bus[n].bus_control = false;
  60. }
  61. }
  62.  
  63. }
  64. for (int i = j; i>=0; i--)
  65. {
  66. if (bus[i].bus_control == false)
  67. {
  68. cout << bus[i].bus_number << " " << bus[i].last_name << " " << bus[i].route_number<<"\n";
  69. }
  70. }
  71. cout << "\n";
  72. for (int i = j; i >= 0; i--)
  73. {
  74. if (bus[i].bus_control == true)
  75. {
  76. cout << bus[i].bus_number << " " << bus[i].last_name << " " << bus[i].route_number<<"\n";
  77. }
  78. }
  79.  
  80. return 0;
  81. }
RAW Paste Data