Advertisement
LADY_PLEASURER_2001

Untitled

Apr 20th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstring>
  4. using  namespace std;
  5. class Car {
  6. protected:
  7.     long long int pos;
  8.  
  9. public:
  10.     Car();                      // По умолчанию, позиция машины равна 0
  11.  
  12.     void move(int direction);   // Сдвинуться по числовой прямой на расстояние direction
  13.                                 // Если direction < 0, то влево
  14.                                 // Если direction > 0, то вправо
  15.  
  16.     int get_position();         // Узнать текущую позицию автомобиля
  17. };
  18. Car::Car() {
  19.     pos = 0;
  20. }
  21. void Car::move(int direction) {
  22.     pos += direction;
  23. }
  24. int Car::get_position() {
  25.     return pos;
  26. }
  27.  
  28.  
  29.  
  30.  
  31. class Bus : public Car {
  32. protected:
  33.     int capacity;
  34.     int passenger_counter;
  35.     int *passengers;
  36. public:
  37.     Bus(int capacity);
  38.     Bus();
  39.     ~Bus();
  40.     bool add_passenger(int destination);
  41.     void release(int destination);
  42.     int get_passenger_count();
  43. };
  44. Bus::Bus(){
  45.   capacity = 0;
  46.   passenger_counter = 0;
  47. }
  48. Bus::Bus(int capacity) {
  49.     this->capacity = capacity;
  50.     passengers = new int[capacity];
  51.     passenger_counter = 0;
  52. }
  53. Bus::~Bus() {
  54.     delete[] passengers;
  55. }
  56. bool Bus::add_passenger(int destination) {
  57.     if (passenger_counter < capacity) {
  58.         passengers[passenger_counter] = destination;
  59.         passenger_counter++;
  60.         return true;
  61.     }
  62.     return false;
  63. }
  64. void Bus::release(int destination) {
  65.     int counter = 0;
  66.     for (int i = 0; i < passenger_counter; ++i) {
  67.         if (passengers[i] == destination) {
  68.             ++counter;
  69.            
  70.             for (int j = i; j < passenger_counter ; ++j) {
  71.                 passengers[j] = passengers[j + 1];
  72.             }
  73.             --i;
  74.         }
  75.     }
  76.     passenger_counter -= counter;
  77. }
  78. int Bus::get_passenger_count() {
  79.     return passenger_counter;
  80. }
  81.  
  82.  
  83.  
  84.  
  85. class Trolleybus: public Bus{
  86.   int L;
  87.   int R;
  88. public:
  89.   Trolleybus(int P, int C, int L, int R);
  90.   void move(int direction);
  91.  
  92. };
  93.  
  94. Trolleybus::Trolleybus(int P,int C, int L, int R){
  95.   Bus(C){
  96.     pos = P
  97.     this->L = L
  98.     this->R = R
  99.   }
  100. }
  101.  
  102.  
  103. int main() {
  104.     int N, cost;
  105.     cin >> N;
  106.     cin >> cost;
  107.     Bus lol(cost);
  108.     for (int i = 0; i < N; ++i) {
  109.         char a[20];
  110.         cin >> a;
  111.         if (a[0] == 'M') {
  112.             int x;
  113.             cin >> x;
  114.             lol.move(x);
  115.         }
  116.         if (a[0] == 'P') {
  117.             if (strlen(a) == 9) {
  118.                 int k;
  119.                 cin >> k;
  120.                 if (lol.add_passenger(k))
  121.                     cout << "SUCCESS" << endl;
  122.                 else
  123.                     cout << ":(" << endl;
  124.             }
  125.             if (strlen(a) == 8) {
  126.                 cout << lol.get_position() << endl;
  127.             }
  128.             if (strlen(a) == 10) {
  129.                 cout << lol.get_passenger_count() << endl;
  130.             }
  131.         }
  132.         if (a[0] == 'R') {
  133.             int b = lol.get_position();
  134.             lol.release(b);
  135.         }
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement