Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cassert>
- #include <algorithm>
- using namespace std;
- class MoneyBox {
- public:
- explicit MoneyBox(vector<int64_t> nominals)
- : nominals_(move(nominals))
- , counts_(nominals_.size()) {
- }
- const vector<int>& GetCounts() const {
- return counts_;
- }
- int GetNominalIdx(int64_t value) {
- return static_cast<int>(find(nominals_.begin(), nominals_.end(), value) - nominals_.begin());
- }
- void PushCoin(int64_t value) {
- // реализуйте метод добавления купюры или монеты
- ++counts_[GetNominalIdx(value)];
- }
- void PrintCoins(ostream& out) const {
- // реализуйте метод печати доступных средств
- for (int i = 0; i < counts_.size(); ++i) {
- if (counts_[i] > 0) {
- out << nominals_[i] << ": "s << counts_[i] << endl;
- }
- }
- }
- private:
- const vector<int64_t> nominals_;
- vector<int> counts_;
- };
- ostream& operator<<(ostream& out, const MoneyBox& cash) {
- cash.PrintCoins(out);
- return out;
- }
- int main() {
- MoneyBox cash({10, 50, 100, 200, 500, 1000, 2000, 5000});
- int times;
- cout << "Enter number of coins you have:"s << endl;
- cin >> times;
- cout << "Enter all nominals:"s << endl;
- for (int i = 0; i < times; ++i) {
- int64_t value;
- cin >> value;
- cash.PushCoin(value);
- }
- cout << cash << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement