Advertisement
yahorrr

Untitled

Nov 24th, 2021
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct sotrudnik
  6. {
  7.     char fio[40];
  8.     int tabelnomer;
  9.     int kolchasov;
  10.     double tarif;
  11. } banksystem[100];
  12.  
  13. void s_vb(sotrudnik* sotrudnik, int n);
  14. void s_qs(sotrudnik* st, int n);
  15. void showSotrudnik(sotrudnik* st, int n);
  16.  
  17. int main()
  18. {
  19.     int n;
  20.     cout << "vvedite kol-vo sotrudnikov: ";
  21.     cin >> n;
  22.     for (int i = 0; i < n; i++) {
  23.         cout << "Vvedite FIO: ";
  24.         cin >> banksystem[i].fio;
  25.         cout << "Vvedite tabelinii nomer: ";
  26.         cin >> banksystem[i].tabelnomer;
  27.         cout << "Vvedite kol-vo chasov: ";
  28.         cin >> banksystem[i].kolchasov;
  29.         cout << "Vvedite po4asovoi tarif: ";
  30.         cin >> banksystem[i].tarif;
  31.         cout << endl;
  32.     }
  33.  
  34.     s_qs(banksystem, n);
  35.     showSotrudnik(banksystem, n);
  36.  
  37. }
  38.  
  39. void s_vb(sotrudnik* sotrudnik, int n)
  40. {
  41.     int imin, t;
  42.     for (int i = 0; i < n - 1; i++) {
  43.         imin = i;
  44.         for (int j = i + 1; j < n; j++)
  45.             if (sotrudnik[imin].kolchasov > sotrudnik[j].kolchasov) imin = j;
  46.         if (imin != i) {
  47.             t = sotrudnik[imin].kolchasov;
  48.             sotrudnik[imin].kolchasov = sotrudnik[i].kolchasov;
  49.             sotrudnik[i].kolchasov = t;
  50.         }
  51.     }
  52. }
  53.  
  54. void s_qs(sotrudnik* st, int n)
  55. {
  56.     struct { int l; int r; }
  57.     stack[20];
  58.     int i, j, left, right, x, s = 0;
  59.     sotrudnik  t;
  60.  
  61.     stack[s].l = 0;
  62.     stack[s].r = n - 1;
  63.     while (s != -1) {
  64.         left = stack[s].l;
  65.         right = stack[s].r;
  66.         s--;
  67.         while (left < right) {
  68.             i = left;
  69.             j = right;
  70.             x = st[(left + right) / 2].kolchasov;
  71.             while (i <= j) {
  72.                 while (st[i].kolchasov < x) i++;
  73.                 while (st[j].kolchasov > x) j--;
  74.                 if (i <= j) {
  75.                     t = st[i];
  76.                     st[i] = st[j];
  77.                     st[j] = t;
  78.                     i++;
  79.                     j--;
  80.                 }
  81.             }
  82.             if ((j - left) < (right - i)) {
  83.                 if (i < right) { s++;  stack[s].l = i;  stack[s].r = right; }
  84.                 right = j;
  85.             }
  86.             else {
  87.                 if (left < j) { s++;  stack[s].l = left;  stack[s].r = j; }
  88.                 left = i;
  89.             }
  90.         }
  91.     }
  92. }
  93.  
  94. void showSotrudnik(sotrudnik* st, int n)
  95. {
  96.     for (int i = 0; i < n; i++)
  97.     {
  98.         cout << "kolichestvo chasov - " << banksystem[i].kolchasov << ' ' << banksystem[i].fio << ' ' << banksystem[i].tabelnomer << ' ' << banksystem[i].tarif << endl;
  99.     }
  100.  
  101.     system("pause");
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement