/
RedResistance
/
wonders
Обзор
Документация
Войти
/
RedResistance
/
wonders
Код
Запросы
2
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
cost.cpp
60 строк
1 KB
Domovoi-Kuzma
T-7 отладка калькулятора оплат
01 мар 2026, 02:09
01 мар 2026, 02:09
7f873f4
Код
Авторство
О чём код?
#include "cost.h" #include <iostream> // ������ int& Cost::operator[](Resource r) { return data[(size_t)r]; } int Cost::operator[](Resource r) const { return data[(size_t)r]; } // ---- ������ ---- bool Cost::is_zero() const { return std::all_of(data.begin(), data.end(), [](int x) { return x == 0; }); } bool Cost::has_any() const { return !is_zero(); } bool Cost::can_cover(const Cost& other) const { // ������� �� �������� for (size_t i = 0; i < data.size(); ++i) if (data[i] < other.data[i]) return false; return true; } // ---- ���������� ---- Cost& Cost::operator+=(const Cost& rhs) { for (size_t i = 0; i < data.size(); ++i) data[i] += rhs.data[i]; return *this; } Cost& Cost::operator-=(const Cost& rhs) { for (size_t i = 0; i < data.size(); ++i) data[i] = std::max(0, data[i] - rhs.data[i]); return *this; } void Cost::add(Resource r, int amount) { data[(size_t)r] += amount; } // �������� ��������� ��� std::set bool Cost::operator<(const Cost& other) const { return data < other.data; // ���������� ������� ����������������� }