Advertisement
yahorrr

Untitled

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