Advertisement
Spocoman

02. Average Student Grades

Jan 18th, 2024
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <queue>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     int n;
  10.     cin >> n;
  11.  
  12.     map<string, queue<double>> students;
  13.  
  14.     string student;
  15.     double grade;
  16.  
  17.     for (size_t i = 0; i < n; i++) {
  18.         cin >> student;
  19.         cin >> grade;
  20.         students[student].push(grade);
  21.     }
  22.  
  23.     for (auto i = students.begin(); i != students.end(); i++) {
  24.         double sumGrades = 0;
  25.  
  26.         cout << i->first << " ->";
  27.  
  28.         int count = i->second.size();
  29.  
  30.         while (i->second.size() != 0) {
  31.             printf(" %.2f", i->second.front());
  32.             sumGrades += i->second.front();
  33.             i->second.pop();
  34.         }
  35.         printf(" (avg: %.2f)\n", sumGrades / count);
  36.     }
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement