Advertisement
Leedwon

Untitled

Jan 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #define MAX_N 10000
  4. /*you can write here*/
  5.  
  6. using namespace std;
  7.  
  8. int tab_int[MAX_N];
  9.  
  10.  
  11. void read(int n) {
  12.     for (int i = 0; i < n; i++)
  13.         cin >> tab_int[i];
  14. }
  15.  
  16. int f0(int n, int tab_empty, int startIteration, bool write) {
  17.     if (tab_empty == 1)
  18.         read(n);
  19.     int Smallest = tab_int[startIteration];
  20.     int positionOfSmallest = startIteration;
  21.  
  22.     for (int i = startIteration; i < n; i++) {
  23.         if (tab_int[i] < Smallest) {
  24.             positionOfSmallest = i;
  25.             Smallest = tab_int[i];
  26.         }
  27.     }
  28.     if (write == true) {
  29.         for (int i = 0; i < n; i++) {
  30.             if (tab_int[i] == Smallest) {
  31.                 cout << i + 1 << " ";
  32.             }
  33.         }
  34.     }
  35.     return positionOfSmallest;
  36. }
  37. void f1(int n , int tab_empty) {
  38.    
  39.     if(tab_empty == 1)
  40.         f0(n, tab_empty, 0, false); // wypelnienie tablicy
  41.     for (int i = 0; i < n; i++) {
  42.         int indexOfsmallest = f0(n, -1, i, false);// -1 w funkcji zeby teraz nie zapisywalo do tablicy
  43.         int temp = tab_int[indexOfsmallest];
  44.         tab_int[indexOfsmallest] = tab_int[i];
  45.         tab_int[i] = temp;
  46.     }
  47.     for (int i = n - 1; i >= 0; i--)
  48.         cout << tab_int[i] << " "; // wypisanie uporzadkowanych wartosci
  49.  
  50. }
  51.  
  52. int main() {
  53.     int subprogram, n;
  54.     while (cin >> subprogram >> n) {
  55.         switch (subprogram) {
  56.         case 0:
  57.             f0(n, 1, 0, true);
  58.             break;
  59.         case 1:
  60.             f1(n, 1);
  61.             break;
  62.         case 2:
  63.             //f2(/*you can write here*/); - not implemented yet
  64.             break;
  65.         case 3:
  66.             //f3(/*you can write here*/); - not implemented yet
  67.             break;
  68.         case 4:
  69.             //f4(/*you can write here*/); - not implemented yet
  70.             break;
  71.  
  72.             /*you can write here*/
  73.  
  74.         }
  75.     };
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement