Advertisement
JosepRivaille

P59282: Mesures estadístiques

Mar 7th, 2016
886
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4.  
  5. int main() {
  6.   cout.setf(ios::fixed);
  7.   cout.precision(4);
  8.   string s;
  9.   int n, max = 0, min = 0, count = 0;
  10.   double ave = 0;
  11.   map<int,int> M;
  12.   map<int,int>::iterator it;
  13.   while (cin >> s) {
  14.     if (s == "number") {
  15.       cin >> n;
  16.       it = M.find(n);
  17.       if (it != M.end()) it->second += 1;
  18.       else M.insert(make_pair(n, 1));
  19.       ave += n;
  20.       ++count;
  21.     }
  22.     else {
  23.       if (!M.empty()) {
  24.     it = M.begin();
  25.     ave -= it->first;
  26.     --count;
  27.     if (it->second == 1) M.erase(it);
  28.     else it->second -= 1;
  29.       }
  30.     }
  31.     if (M.empty()) cout << "no elements" << endl;
  32.     else {
  33.       it = M.end();
  34.       --it;
  35.       cout << "minimum: " << M.begin()->first << ", maximum: " << it->first << ", average: " << ave/count << endl;
  36.     }
  37.   }
  38. }
  39.  
  40. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement