Advertisement
qberik

Untitled

Dec 16th, 2021
1,001
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. #define SIZE 100
  5. using namespace std;
  6.  
  7. struct Stud{
  8.   char name[SIZE];
  9.   char group[SIZE];
  10.   float avg;
  11.   int dis;
  12. };
  13.  
  14.  
  15.  
  16.  
  17. int main(){
  18.   Stud s[SIZE];
  19.   Stud s1[SIZE];
  20.  
  21.   int count = 0;
  22.   ifstream file("t.txt");
  23.  
  24.   char c;
  25.   for( int i = 0; !file.eof(); i++ ){
  26.     file >> s[i].name >> s[i].group >> s[i].avg;
  27.     s[i].dis = -1;
  28.     for( int j = 0; j < 5; j++ ){
  29.       file >> c;
  30.       if ( c == '*' )
  31.         s[i].dis = j + 1;
  32.     }
  33.     if( s[i].dis != -1 )  
  34.       count++;
  35.   }
  36.  
  37.  
  38.   int in;
  39.   cout << "Введите номер дисциплины ( 1 - 5 )" << endl;
  40.   cin >> in;
  41.  
  42.   int count_dis = 0;
  43.   for( int i = 0; i < count; i++ ){
  44.     if( s[i].dis == in ){
  45.       s1[count_dis] = s[i];
  46.       count_dis++;
  47.     }
  48.   }
  49.  
  50.   if( count_dis > 10 ){
  51.     for( int i = 0; i < count_dis - 1; i++ ){
  52.       int min = i;
  53.       for( int j = i; j < count_dis; j++ )
  54.         if( s1[j].avg > s1[min].avg )
  55.           min = j;
  56.       if( min != i ){
  57.         Stud tmp = s1[i];
  58.         s1[i] =  s1[min];
  59.         s1[min] = tmp;
  60.       }
  61.     }
  62.     count_dis = 10;
  63.   }
  64.  
  65.   for( int i = 0; i < count_dis; i++ ){
  66.     cout << "" << s1[i].name << ' ' << s1[i].group << ' ' << s1[i].avg << " Дисциплина под номером " << s1[i].dis << endl;
  67.   }
  68.  
  69.  
  70.   return 0;
  71. }
  72.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement