Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Экономические сложности*/
- /*
- Знаменательный день превратился в знаменательную неделю и все новые и новые фракции присоединяются к Галактическому Содружеству, но пока политики празднуют, у экономистов и торговых компаний раскалывается голова. Валют стало еще больше, и вслед за буллами, старсами и борками, добавились лурки и кванги. А что дальше будет, мы даже боимся представить. К тому же из-за появления новых валют курс космокредита постоянно меняется.
- Чтобы решить эту проблему мы выслали промышленного шпиона в Лирианский Консорциум, чтобы тот смог выкрасть коды их торговых модулей. Всем известно, что они лучшие в этом.
- Вот, что ему удалось раздобыть:
- class SpaceCurrency {
- public:
- // Курс валюты по отношению к космокредиту
- double rate = 0;
- string name;
- void read() {
- cin >> name >> rate;
- }
- int toCosmoCredits(int count) {
- return count*rate;
- }
- };
- Так же они использовали vector<SpaceCurrency>, чтобы решить проблему с конвертированием валют. Мы надеемся, что вы сможете разобраться в сложившейся ситуации и доработать наши торговые модули.
- Входные данные:
- Корабль:
- * как и ранее
- Валюты:
- * количество пар (int) пары - "имя" (string) "курс к космокредиту" (double)
- Команды:
- * как и ранее
- */
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <vector>
- using namespace std;
- // координаты объекта в космосе
- class SpacePoint {
- public:
- int X, Y;
- int distance(SpacePoint point) {
- return sqrt(pow(X - point.X, 2) + pow(Y - point.Y, 2));
- }
- void read() {
- cin >> X >> Y;
- }
- void print() {
- cout << "Cordinates: x=" << X << " y=" << Y << endl;
- }
- };
- class SpaceCurrency {
- public:
- // Курс валюты по отношению к космокредиту
- double rate = 0;
- string name;
- void read() {
- cin >> name >> rate;
- }
- int toCosmoCredits(int count) {
- return count*rate;
- }
- };
- // Денежный счет
- class CreditAccount {
- public:
- // Галактические кредиты
- int credits;
- vector<SpaceCurrency> currencies;
- void putCredits(int count) {
- credits += count;
- }
- void putCurrency(string name, int count) {
- for (int i = 0; i < currencies.size(); i++) {
- if (currencies[i].name == name) {
- credits += currencies[i].toCosmoCredits(count);
- break;
- }
- }
- }
- void read() {
- cin >> credits;
- int ccount;
- cin >> ccount;
- for (int i = 0; i < ccount; i++) {
- SpaceCurrency sc;
- sc.read();
- currencies.push_back(sc);
- }
- }
- void printSatus() {
- cout << "Account: " << credits << " credits" << endl;
- }
- };
- class SpaceShip {
- public:
- // Остаток топлива
- int fuelLeft;
- // Вместимость топливного бака (максимум топлива)
- int fuelMax;
- // Название корабля
- string name;
- //Координаты корабля
- SpacePoint pos;
- // Денежный счет
- CreditAccount account;
- void printStatus() {
- cout << "STATUS: " << name << endl;
- pos.print();
- cout << "Fuel: " << fuelLeft << " from " << fuelMax << endl;
- account.printSatus();
- }
- void flight(SpacePoint pt) {
- fuelLeft -= pos.distance(pt);
- if (fuelLeft < 0)
- fuelLeft = 0;
- pos = pt;
- }
- void prepare() {
- cin >> name >> fuelLeft >> fuelMax;
- pos.read();
- account.read();
- }
- };
- int main() {
- SpaceShip ship;
- ship.prepare();
- int comCount;
- cin >> comCount;
- for (int i = 0; i < comCount; i++) {
- string com;
- cin >> com;
- if (com == "flight") {
- SpacePoint pt;
- pt.read();
- ship.flight(pt);
- }
- if (com == "buy") {
- int count;
- cin >> count;
- ship.account.credits -= count;
- }
- if (com == "cache") {
- int count;
- string name;
- cin >> count >> name;
- if (name == "credits")
- ship.account.putCredits(count);
- else
- ship.account.putCurrency(name, count);
- }
- if (com == "status")
- ship.printStatus();
- }
- }
- /*
- Тест 1
- Ввод:
- Enterprise 120 120 167 120 0
- 5 borks 4 stars 0.5 bools 3.5 qvangs 12 lurs 0.2
- 4
- cache 300 borks
- cache 1000 lurs
- cache 10 qvangs
- status
- Вывод:
- STATUS: Enterprise
- Cordinates: x=167 y=120
- Fuel: 120 from 120
- Account: 1520 credits
- Тест 2
- Ввод:
- Enterprise 120 120 167 120 0
- 4 stars 0.4 bools 3 qvangs 10 lurs 0.1
- 6
- flight 130 114
- cache 300 bools
- buy 600
- cache 1000 lurs
- cache 4200 stars
- status
- Вывод:
- STATUS: Enterprise
- Cordinates: x=130 y=114
- Fuel: 83 from 120
- Account: 2080 credits
- Тест 3
- Ввод:
- Enterprise 120 120 167 120 0
- 4 stars 0.5 bools 3.5 qvangs 12 lurs 0.2
- 12
- flight 130 114
- cache 300 bools
- buy 600
- cache 1000 lurs
- flight 100 90
- cache 1000 stars
- buy 1000
- cache 1000 qvangs
- flight 90 90
- buy 100
- cache 1000 credits
- status
- Вывод:
- STATUS: Enterprise
- Cordinates: x=90 y=90
- Fuel: 35 from 120
- Account: 13050 credits
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement