Advertisement
Leedwon

Untitled

Jan 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 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.  
  42.     cout << endl;
  43.  
  44.     for (int i = 0; i < n; i++) {
  45.         int indexOfsmallest = f0(n, -1, i, false);// -1 w funkcji zeby teraz nie zapisywalo do tablicy
  46.         int temp = tab_int[indexOfsmallest];
  47.         tab_int[indexOfsmallest] = tab_int[i];
  48.         tab_int[i] = temp;
  49.     }
  50.     for (int i = 0; i < n; i++)
  51.         cout << tab_int[i] << " "; // wypisanie uporzadkowanych wartosci
  52.  
  53. }
  54.  
  55. int main() {
  56.     int subprogram, n;
  57.     while (cin >> subprogram >> n) {
  58.         switch (subprogram) {
  59.         case 0:
  60.             f0(n, 1, 0, true);
  61.             break;
  62.         case 1:
  63.             f1(n, 1);
  64.             break;
  65.         case 2:
  66.             //f2(/*you can write here*/); - not implemented yet
  67.             break;
  68.         case 3:
  69.             //f3(/*you can write here*/); - not implemented yet
  70.             break;
  71.         case 4:
  72.             //f4(/*you can write here*/); - not implemented yet
  73.             break;
  74.  
  75.             /*you can write here*/
  76.  
  77.         }
  78.     };
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement