Advertisement
Leedwon

Untitled

Jan 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 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. void read(int n) {
  11.     for (int i = 0; i < n; i++)
  12.         cin >> tab_int[i];
  13. }
  14.  
  15. int f0(int n, int tab_empty, int startIteration) {
  16.     if (tab_empty == 1)
  17.         read(n);
  18.     int Smallest = tab_int[startIteration];
  19.     int positionOfSmallest = startIteration;
  20.  
  21.     for (int i = startIteration; i < n; i++) {
  22.         if (tab_int[i] < Smallest) {
  23.             positionOfSmallest = i;
  24.             Smallest = tab_int[i];
  25.         }
  26.     }
  27.     for (int i = 0; i < n; i++) {
  28.         if (tab_int[i] == Smallest) {
  29.             cout << i + 1 << " ";
  30.         }
  31.     }
  32.     cout << endl;
  33.     return positionOfSmallest;
  34. }
  35. void f1(int n , int tab_empty) {
  36.    
  37.     if(tab_empty == 1)
  38.         f0(n, tab_empty, 0); // wypelnienie tablicy
  39.  
  40.     for (int i = 0; i < n; i++) {
  41.         cout << endl;
  42.         int indexOfsmallest = f0(n, -1, i);// -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 = 0; i < n; 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);
  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