Advertisement
Kocyk

flagaalgo

Mar 18th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. using namespace std;
  5. struct student
  6. {
  7.     int index;
  8.     float ocena;
  9. };
  10. int flagapolska(student studenci[],int n)
  11. {
  12.  int p=0, k=n-1, ostatniadobra=-1;
  13.  while(p<k)
  14.  {
  15.     while(p<n-1 && studenci[p].ocena>=3) p++;
  16.     while(k>=0 && studenci[k].ocena<3) k--;
  17.     if(p<k)
  18.     {
  19.     swap(studenci[p],studenci[k]);
  20.    
  21.     }
  22.  //   p++;
  23.  //   k--;
  24.     if(studenci[p].ocena > 3)ostatniadobra=p;
  25.     else ostatniadobra=p-1;
  26.  }
  27.  return ostatniadobra;
  28. }
  29. void wyswietlaniezdanych(student studenci[],int ost)
  30. {
  31.     for(int i=0;i<=ost;i++)
  32.     {
  33.         cout<<studenci[i].index<<endl;
  34.         cout<<studenci[i].ocena<<endl;
  35.     }
  36. }
  37. void wyswietlanieniezdanych(student studenci[],int ost,int n)
  38. {
  39.     for(int i=ost+1;i<n;i++)
  40.     {
  41.         cout<<studenci[i].index<<endl;
  42.         cout<<studenci[i].ocena<<endl;
  43.     }
  44. }
  45. int main()
  46. {
  47.     int n,ocn;
  48.     srand( time( NULL ) );
  49.    
  50.     cout<<"Podaj ile jest studentow"<<endl;
  51.     cin>>n;
  52.     student studenci[n];
  53.     for(int i=0;i<n;i++)
  54.     {
  55.         studenci[i].index=(rand()%99999+10000);
  56.         do{
  57.             cout<<"Podaj ocene studenta z indeksem: "<<studenci[i].index<<endl;
  58.             cin>>ocn;
  59.             if(ocn!=3 && ocn!=4 && ocn!=5 && ocn!=2 && ocn!=3.5 && ocn!=4.5) cout<<"Bledna ocena!"<<endl;
  60.         }while(ocn!=3 && ocn!=4 && ocn!=5 && ocn!=2 && ocn!=3.5 && ocn!=4.5);
  61.         studenci[i].ocena=ocn;
  62.        
  63.     }
  64.    
  65.    
  66.     int ost=flagapolska(studenci,n);
  67.     cout<<"Zdali: "<<endl;
  68.     wyswietlaniezdanych(studenci,ost);
  69.    
  70.     cout<<"Niezdali: "<<endl;
  71.     wyswietlanieniezdanych(studenci,ost,n);
  72.     return 0;
  73.    
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement