Advertisement
0xPaulius

n2

Oct 20th, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. struct mokinys{
  6.     string name;
  7.     int paz[100];
  8.     int pcount = 0;
  9.     double sum = 0;
  10. };
  11.  
  12. int main()
  13. {
  14.     mokinys student[100];
  15.     int scount = 0;
  16.     double max = 0;
  17.     char comma;
  18.  
  19.     ifstream in("Duota2.txt");
  20.  
  21.     while(!in.eof())
  22.     {
  23.         getline(in, student[scount].name, ',');
  24.         string S;
  25.         getline(in, S);
  26.  
  27.         int s = 0;
  28.         for(int i = 0; i < S.size(); i++){
  29.             if(S[i] == ' ') continue;
  30.             if(S[i] == ',') {
  31.                 student[scount].paz[student[scount].pcount++] = s;
  32.                 s = 0;
  33.             }else s = s*10 + S[i] - '0';
  34.         }
  35.         student[scount].paz[student[scount].pcount++] = s;
  36.         in >> ws;
  37.         scount++;
  38.     }
  39.  
  40.     in.close();
  41.  
  42.     for(int i = 0; i < scount; i++)
  43.     {
  44.         for(int j = 0; j < student[i].pcount; j++)
  45.         {
  46.             student[i].sum += student[i].paz[j];
  47.         }
  48.     }
  49.  
  50.     for(int i = 0; i < scount; i++)
  51.     {
  52.         student[i].sum /= double(student[i].pcount);
  53.         if(student[i].sum > max)
  54.         {
  55.             max = student[i].sum;
  56.         }
  57.     }
  58.  
  59.     ofstream out("Rezultatas.txt");
  60.  
  61.     for(int i = 0; i < scount; i++)
  62.     {
  63.         if(student[i].sum == max)
  64.         {
  65.             out << student[i].name;
  66.         }
  67.     }
  68.  
  69.     out.close();
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement