Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstring>
- using namespace std;
- class Car {
- protected:
- long long int pos;
- public:
- Car(); // По умолчанию, позиция машины равна 0
- void move(int direction); // Сдвинуться по числовой прямой на расстояние direction
- // Если direction < 0, то влево
- // Если direction > 0, то вправо
- int get_position(); // Узнать текущую позицию автомобиля
- };
- Car::Car() {
- pos = 0;
- }
- void Car::move(int direction) {
- pos += direction;
- }
- int Car::get_position() {
- return pos;
- }
- class Bus : public Car {
- protected:
- int capacity;
- int passenger_counter;
- int *passengers;
- public:
- Bus(int capacity);
- Bus();
- ~Bus();
- bool add_passenger(int destination);
- void release(int destination);
- int get_passenger_count();
- };
- Bus::Bus(){
- capacity = 0;
- passenger_counter = 0;
- }
- Bus::Bus(int capacity) {
- this->capacity = capacity;
- passengers = new int[capacity];
- passenger_counter = 0;
- }
- Bus::~Bus() {
- delete[] passengers;
- }
- bool Bus::add_passenger(int destination) {
- if (passenger_counter < capacity) {
- passengers[passenger_counter] = destination;
- passenger_counter++;
- return true;
- }
- return false;
- }
- void Bus::release(int destination) {
- int counter = 0;
- for (int i = 0; i < passenger_counter; ++i) {
- if (passengers[i] == destination) {
- ++counter;
- for (int j = i; j < passenger_counter ; ++j) {
- passengers[j] = passengers[j + 1];
- }
- --i;
- }
- }
- passenger_counter -= counter;
- }
- int Bus::get_passenger_count() {
- return passenger_counter;
- }
- class Trolleybus: public Bus{
- int L;
- int R;
- public:
- Trolleybus(int P, int C, int L, int R);
- void move(int direction);
- };
- Trolleybus::Trolleybus(int P,int C, int L, int R){
- Bus(C){
- pos = P
- this->L = L
- this->R = R
- }
- }
- int main() {
- int N, cost;
- cin >> N;
- cin >> cost;
- Bus lol(cost);
- for (int i = 0; i < N; ++i) {
- char a[20];
- cin >> a;
- if (a[0] == 'M') {
- int x;
- cin >> x;
- lol.move(x);
- }
- if (a[0] == 'P') {
- if (strlen(a) == 9) {
- int k;
- cin >> k;
- if (lol.add_passenger(k))
- cout << "SUCCESS" << endl;
- else
- cout << ":(" << endl;
- }
- if (strlen(a) == 8) {
- cout << lol.get_position() << endl;
- }
- if (strlen(a) == 10) {
- cout << lol.get_passenger_count() << endl;
- }
- }
- if (a[0] == 'R') {
- int b = lol.get_position();
- lol.release(b);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement