Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. struct Student
  4. {
  5.     int index, result;
  6. };
  7.  
  8. int flaga01(int n, Student Tab[])
  9. {   int zero,one;
  10.  
  11.     int i=1;
  12.     int j=n;
  13.  
  14.     while(i<j)
  15.     {
  16.         if(Tab[i].result==1)i++;
  17.         else
  18.         {
  19.             while (Tab[j].result==0 && i<j) j--;
  20.             if(i<j)
  21.             {
  22.                 int pom;
  23.                 pom=Tab[i].result;
  24.                 Tab[i].result=Tab[j].result;
  25.                 Tab[j].result=pom;
  26.                 j--;
  27.  
  28.             }
  29.         }
  30.     }
  31.  
  32.  
  33.     return i;
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39.     int n;
  40.     std::cout<< "podaj liczbe studentow" <<std::endl;
  41.     std::cin >> n;
  42.     Student Tab[n];
  43.     for(int i=0 ; i < n ; i++)
  44.     {
  45.         std::cout<<"Podaj numer indeksu " << i+1 <<"osoby" << std::endl;
  46.         std::cin >> Tab[i].index;
  47.         std::cout<<"podaj ocene" <<i+1 <<"osoby" << std::endl;
  48.         std::cin >> Tab[i].result;
  49.  
  50.     }
  51.  
  52.     int zdali = flaga01(n, Tab);
  53.     system("CLS");
  54.     for(int i = 0; i < n ; i++)
  55.     {
  56.     std::cout << Tab[i].index <<" " << Tab[i].result << std::endl;
  57.  
  58.     }
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement