Advertisement
ProgramoBien

P81104 F001A. Students at the FIPS

Dec 11th, 2017
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct Subject {
  7.     string name;
  8.     double mark;
  9. };
  10.  
  11. struct Student {
  12.     string name;
  13.     int idn;
  14.     vector<Subject> sub;
  15. };
  16.  
  17. double mark(const vector<Student>& stu, int idn, string name){
  18.     bool f = true;
  19.     for(int i = 0; i < stu.size() and f; ++i){
  20.         Student st = stu[i];
  21.         if(st.idn == idn){
  22.             for(int s = 0; s < st.sub.size(); ++s){
  23.                 if(st.sub[s].name == name && st.sub[s].mark >= 0)
  24.                     return st.sub[s].mark;
  25.             }
  26.             f = false;
  27.         }
  28.     }
  29.     return -1;
  30. }
  31.  
  32. double mean(const vector<Subject>& sub){
  33.     double m = 0;
  34.     int c = 0;
  35.     for(int i = 0 ;i < sub.size(); ++i){
  36.         if(sub[i].mark >= 0){
  37.             ++c;
  38.             m += sub[i].mark;
  39.         }
  40.     }
  41.     return m/c;
  42. }
  43.  
  44. void count(const vector<Student>& stu, int idn, string name, int& counter){
  45.     counter = 0;
  46.     double n = mark(stu, idn, name);
  47.     for(int i = 0; i < stu.size(); ++i){
  48.         Student s = stu[i];
  49.         if(mean(s.sub) > n)
  50.             counter++;
  51.     }
  52. }
  53.  
  54. int main() {
  55.     int n;
  56.     cin >> n;
  57.     vector<Student> v(n);
  58.     int j = 0;
  59.     while(n--){
  60.         cin >> v[j].name >> v[j].idn;
  61.         int ns;
  62.         cin >> ns;
  63.         int i = 0;
  64.         vector<Subject> vs(ns);
  65.         while(i < ns){
  66.             cin >> vs[i].name >> vs[i].mark;
  67.             ++i;
  68.         }
  69.         v[j].sub = vs;
  70.         ++j;
  71.     }
  72.     int i;
  73.     string s;
  74.     while(cin >> i >> s){
  75.         int c;
  76.         count(v, i, s, c);
  77.         cout << c << endl;
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement