You are on page 1of 4

// Variant 2

// 1
#include <bits/stdc++.h>

using namespace std;

class Worker {
string name;
int productivity;
int salary;
public:
Worker() {
cin >> name >> productivity >> salary;
}

int getSalary() {
return salary;
}

int getProductivity() {
return productivity;
}
};

class Mechanism {
string name;
int details;
int cost;
int wCount;
Worker *workers;
public:
Mechanism() {
cin >> name >> details >> cost >> wCount;
workers = new Worker[wCount];
}

Worker getWorker(int i) {
return workers[i];
}

string getName() {
return name;
}

int amountOfDetails() {
int details = 0;
for (int i = 0; i < wCount; i++) {
details += getWorker(i).getProductivity();
}
return details;
}

int sumSalary() {
int salary = 0;
for (int i = 0; i < wCount; i++) {
salary += getWorker(i).getSalary();
}
return salary;
}
int month() {
return ceil(details / double(amountOfDetails()));
}

int total() {
return cost - (month() * sumSalary());
}
};

int main() {
int size;
cin >> size;

int sum = 0;
for (int i = 0; i < size; ++i) {
Mechanism mechanism;
cout << mechanism.getName() << " = " << mechanism.total() << '\n';
sum += mechanism.total();
}
cout << "Total income = " << sum;
}

// 2
#include <iostream>
#include <vector>

using namespace std;

class Student {
private:
string name;
string course;
int money;
public:
Student() {
cin >> name >> course >> money;
}

const string &getName() const {


return name;
}

const string &getCourse() const {


return course;
}

int getMoney() const {


return money;
}
};

class Course {
private:
string name;
int minStudents{}, cost{};
vector<Student> listOfStudents;
public:
Course() {
cin >> name >> minStudents >> cost;
}

void pushBackToListOfStudents(Student student) {


listOfStudents.push_back(student);
}

const int &getCost() const {


return cost;
}

const string &getName() const {


return name;
}

int getMinStudents() const {


return minStudents;
}

int calculateProfit() {
int profit = 0;
for (Student iter: listOfStudents) {
profit += cost;
}

return profit;
}

const vector<Student> &getListOfStudents() const {


return listOfStudents;
}
};

int main() {
int n, m;
cin >> n;
vector<Course> courses(n);

for (int i = 0; i < n; i++) {


courses[i];
}

cin >> m;

vector<Student> students(m);

for (int j = 0; j < m; j++) {


students[j];
}

for (int i = 0; i < n; i++) {


for (int j = 0; j < m; j++) {
if (courses[i].getName() == students[j].getCourse() &&
courses[i].getCost() <= students[j].getMoney()) {
courses[i].pushBackToListOfStudents(students[j]);
}
}

if (courses[i].getMinStudents() <= courses[i].getListOfStudents().size()) {


cout << courses[i].getName() << ' ' << courses[i].calculateProfit() <<
endl;
for (Student iter: courses[i].getListOfStudents()) {
cout << iter.getName() << endl;
}
}
}
}

You might also like