Advertisement
cd62131

average

Apr 14th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <map>
  4. #include <iomanip>
  5. using namespace std;
  6. int main() {
  7.   const int n = 21;
  8.   map<int, int> sum, size, pass;
  9.   int id, group, score;
  10.   for (int i = 0; i < n; i++) sum[i] = size[i] = pass[i] = 0;
  11.   ifstream fin("itiran.csv");
  12.   while (fin >> id >> group >> score) {
  13.     sum[group] += score;
  14.     size[group]++;
  15.     if (score > 80) pass[group]++;
  16.   }
  17.   for (auto& e: sum) {
  18.     if (e.first == 0) continue;
  19.     if (size[e.first] == 0) {
  20.       cout << e.first << ' ' << '-' << ' ' << '-' << ' ' << '-' << endl;
  21.       continue;
  22.     }
  23.     cout << e.first << ' ' << size[e.first] << ' '
  24.         << ((double) e.second) / size[e.first] << ' '
  25.         << ((double) pass[e.first]) / size[e.first] << endl;
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement