Advertisement
Leedwon

Untitled

Jan 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 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[0];
  19.     int positionOfSmallest = 0;
  20.  
  21.     for (int i = startIteration; i < n; i++) {
  22.         if (tab_int[i] < Smallest) {
  23.             Smallest = tab_int[i];
  24.         }
  25.     }
  26.     for (int i = 0; i < n; i++) {
  27.         if (tab_int[i] == Smallest) {
  28.             cout << i + 1 << " ";
  29.         }
  30.     }
  31.     cout << endl;
  32.     return positionOfSmallest;
  33. }
  34. void f1(int n , int tab_empty) {
  35.    
  36.     if(tab_empty == 1)
  37.         f0(n, tab_empty, 0); // wypelnienie tablicy
  38.  
  39.     for (int i = 0; i < n; i++) {
  40.         cout << endl;
  41.         int indexOfsmallest = f0(n, -1, i);// -1 w funkcji zeby teraz nie zapisywalo do tablicy
  42.         int temp = tab_int[indexOfsmallest];
  43.         tab_int[indexOfsmallest] = tab_int[i];
  44.         tab_int[i] = temp;
  45.     }
  46.     for (int i = 0; i < n; i++)
  47.         cout << tab_int[i] << " "; // wypisanie uporzadkowanych wartosci
  48.  
  49. }
  50.  
  51. int main() {
  52.     int subprogram, n;
  53.     while (cin >> subprogram >> n) {
  54.         switch (subprogram) {
  55.         case 0:
  56.             f0(n, 1, 0);
  57.             break;
  58.         case 1:
  59.             f1(n, 1);
  60.             break;
  61.         case 2:
  62.             //f2(/*you can write here*/); - not implemented yet
  63.             break;
  64.         case 3:
  65.             //f3(/*you can write here*/); - not implemented yet
  66.             break;
  67.         case 4:
  68.             //f4(/*you can write here*/); - not implemented yet
  69.             break;
  70.  
  71.             /*you can write here*/
  72.  
  73.         }
  74.     };
  75.     return 0;
  76. }#include <iostream>
  77.  
  78. #define MAX_N 10000
  79. /*you can write here*/
  80.  
  81. using namespace std;
  82.  
  83. int tab_int[MAX_N];
  84.  
  85. void read(int n) {
  86.     for (int i = 0; i < n; i++)
  87.         cin >> tab_int[i];
  88. }
  89.  
  90. int f0(int n, int tab_empty, int startIteration) {
  91.     if (tab_empty == 1)
  92.         read(n);
  93.     int Smallest = tab_int[0];
  94.     int positionOfSmallest = 0;
  95.  
  96.     for (int i = startIteration; i < n; i++) {
  97.         if (tab_int[i] < Smallest) {
  98.             Smallest = tab_int[i];
  99.         }
  100.     }
  101.     for (int i = 0; i < n; i++) {
  102.         if (tab_int[i] == Smallest) {
  103.             cout << i + 1 << " ";
  104.         }
  105.     }
  106.     cout << endl;
  107.     return positionOfSmallest;
  108. }
  109. void f1(int n , int tab_empty) {
  110.    
  111.     if(tab_empty == 1)
  112.         f0(n, tab_empty, 0); // wypelnienie tablicy
  113.  
  114.     for (int i = 0; i < n; i++) {
  115.         cout << endl;
  116.         int indexOfsmallest = f0(n, -1, i);// -1 w funkcji zeby teraz nie zapisywalo do tablicy
  117.         int temp = tab_int[indexOfsmallest];
  118.         tab_int[indexOfsmallest] = tab_int[i];
  119.         tab_int[i] = temp;
  120.     }
  121.     for (int i = 0; i < n; i++)
  122.         cout << tab_int[i] << " "; // wypisanie uporzadkowanych wartosci
  123.  
  124. }
  125.  
  126. int main() {
  127.     int subprogram, n;
  128.     while (cin >> subprogram >> n) {
  129.         switch (subprogram) {
  130.         case 0:
  131.             f0(n, 1, 0);
  132.             break;
  133.         case 1:
  134.             f1(n, 1);
  135.             break;
  136.         case 2:
  137.             //f2(/*you can write here*/); - not implemented yet
  138.             break;
  139.         case 3:
  140.             //f3(/*you can write here*/); - not implemented yet
  141.             break;
  142.         case 4:
  143.             //f4(/*you can write here*/); - not implemented yet
  144.             break;
  145.  
  146.             /*you can write here*/
  147.  
  148.         }
  149.     };
  150.     return 0;
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement