Advertisement
Spocoman

03. Cash Joint

Feb 17th, 2024
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. bool is_find(vector<string>& v, string el) {
  10.     return find(v.begin(), v.end(), el) != v.end();
  11. }
  12. int main() {
  13.     map<string, double> account;
  14.     vector<string> currencies;
  15.  
  16.     string CURRENCY_TICKER, currency, sum;
  17.     cin >> CURRENCY_TICKER;
  18.  
  19.     while (CURRENCY_TICKER != "END") {
  20.         cin >> sum;
  21.         account[CURRENCY_TICKER] += stod(sum);
  22.         if (!is_find(currencies, CURRENCY_TICKER)) {
  23.             currencies.push_back(CURRENCY_TICKER);
  24.         }      
  25.         cin >> CURRENCY_TICKER;
  26.     }
  27.  
  28.     cin >> CURRENCY_TICKER;
  29.  
  30.     while (CURRENCY_TICKER != "END") {
  31.         if (CURRENCY_TICKER == "+" || CURRENCY_TICKER == "-") {
  32.             cin >> currency >> sum;
  33.             account[currency] += (CURRENCY_TICKER == "+" ? stod(sum) : -stod(sum));
  34.         }
  35.         else if (CURRENCY_TICKER == "X") {
  36.             cin >> currency >> sum;
  37.             double s = stod(sum);
  38.             account[currency] -= s;
  39.             cin >> currency >> sum;
  40.             s *= stod(sum);
  41.             account[currency] += s;
  42.         }
  43.         else {
  44.             for (auto& c : currencies) {
  45.                 printf("%s: %.2f\n", c.c_str(), account[c]);
  46.             }
  47.         }
  48.         cin >> CURRENCY_TICKER;
  49.     }
  50.        
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement