Advertisement
Guest User

Burse Studenti

a guest
Aug 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iomanip>
  5.  
  6. struct Student{
  7.     char nume[100];
  8.     std::vector<int> note;
  9.     float medie;
  10.     bool integralist;
  11. };
  12.  
  13.  
  14. float calcMedie(std::vector<int> note, int n){
  15.     float medie;
  16.     int suma = 0;
  17.     for(unsigned int i = 0; i < n; i++){
  18.         suma+=note[i];
  19.     }
  20.     medie = suma / n;
  21.     return medie;
  22. }
  23.  
  24. bool statut(std::vector<int> note, int n){
  25.     bool status = true;
  26.     for(unsigned int i = 0; i < n; i++){
  27.         if(note[i] < 5){
  28.             status = false;
  29.             break;
  30.         }
  31.     }
  32.     return status;
  33. }
  34.  
  35. bool wayToSort(const Student &lhs, const Student &rhs){
  36.     return lhs.medie > rhs.medie;
  37. }
  38.  
  39. int main(){
  40.     int m, n, p;
  41.     int burseAcordate = 0;
  42.     std::cin >> m >> n >> p;
  43.    
  44.     std::vector<Student> studenti(m);
  45.    
  46.     //fill students with marks and average
  47.     for(unsigned int i = 0; i < m; i++){
  48.         std::cin >> studenti[i].nume;
  49.         for(unsigned int j = 0; j < n; j++){
  50.             std::cin >> studenti[i].note[j];
  51.         }
  52.         studenti[i].medie = calcMedie(studenti[i].note, n);
  53.         studenti[i].integralist = statut(studenti[i].note, n);
  54.     }
  55.    
  56.     //sort by medie
  57.     std::sort(studenti.begin(), studenti.end(), wayToSort);
  58.    
  59.  
  60.     //give bursa to first p integralsiti
  61.     for(unsigned int i = 0; i < m; i++){
  62.         if(studenti[i].integralist && studenti[i].medie > 8.00 && p > 0){
  63.             burseAcordate++;
  64.             p--;
  65.             if(p == 0){
  66.                 break;
  67.             }
  68.         }
  69.     }
  70.    
  71.     std::cout << burseAcordate << std::endl;
  72.     std::cout << studenti[0].nume << " " << std::fixed << std::setprecision(2) << studenti[0].medie;  
  73.    
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement