Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define MAX_N 10000
- /*you can write here*/
- using namespace std;
- int tab_int[MAX_N];
- void read(int n) {
- for (int i = 0; i < n; i++)
- cin >> tab_int[i];
- }
- int f0(int n, int tab_empty, int startIteration) {
- if (tab_empty == 1)
- read(n);
- int Smallest = tab_int[0];
- int positionOfSmallest = 0;
- for (int i = startIteration; i < n; i++) {
- if (tab_int[i] < Smallest) {
- Smallest = tab_int[i];
- }
- }
- for (int i = 0; i < n; i++) {
- if (tab_int[i] == Smallest) {
- cout << i + 1 << " ";
- }
- }
- cout << endl;
- return positionOfSmallest;
- }
- void f1(int n , int tab_empty) {
- if(tab_empty == 1)
- f0(n, tab_empty, 0); // wypelnienie tablicy
- for (int i = 0; i < n; i++) {
- cout << endl;
- int indexOfsmallest = f0(n, -1, i);// -1 w funkcji zeby teraz nie zapisywalo do tablicy
- int temp = tab_int[indexOfsmallest];
- tab_int[indexOfsmallest] = tab_int[i];
- tab_int[i] = temp;
- }
- for (int i = 0; i < n; i++)
- cout << tab_int[i] << " "; // wypisanie uporzadkowanych wartosci
- }
- int main() {
- int subprogram, n;
- while (cin >> subprogram >> n) {
- switch (subprogram) {
- case 0:
- f0(n, 1, 0);
- break;
- case 1:
- f1(n, 1);
- break;
- case 2:
- //f2(/*you can write here*/); - not implemented yet
- break;
- case 3:
- //f3(/*you can write here*/); - not implemented yet
- break;
- case 4:
- //f4(/*you can write here*/); - not implemented yet
- break;
- /*you can write here*/
- }
- };
- return 0;
- }#include <iostream>
- #define MAX_N 10000
- /*you can write here*/
- using namespace std;
- int tab_int[MAX_N];
- void read(int n) {
- for (int i = 0; i < n; i++)
- cin >> tab_int[i];
- }
- int f0(int n, int tab_empty, int startIteration) {
- if (tab_empty == 1)
- read(n);
- int Smallest = tab_int[0];
- int positionOfSmallest = 0;
- for (int i = startIteration; i < n; i++) {
- if (tab_int[i] < Smallest) {
- Smallest = tab_int[i];
- }
- }
- for (int i = 0; i < n; i++) {
- if (tab_int[i] == Smallest) {
- cout << i + 1 << " ";
- }
- }
- cout << endl;
- return positionOfSmallest;
- }
- void f1(int n , int tab_empty) {
- if(tab_empty == 1)
- f0(n, tab_empty, 0); // wypelnienie tablicy
- for (int i = 0; i < n; i++) {
- cout << endl;
- int indexOfsmallest = f0(n, -1, i);// -1 w funkcji zeby teraz nie zapisywalo do tablicy
- int temp = tab_int[indexOfsmallest];
- tab_int[indexOfsmallest] = tab_int[i];
- tab_int[i] = temp;
- }
- for (int i = 0; i < n; i++)
- cout << tab_int[i] << " "; // wypisanie uporzadkowanych wartosci
- }
- int main() {
- int subprogram, n;
- while (cin >> subprogram >> n) {
- switch (subprogram) {
- case 0:
- f0(n, 1, 0);
- break;
- case 1:
- f1(n, 1);
- break;
- case 2:
- //f2(/*you can write here*/); - not implemented yet
- break;
- case 3:
- //f3(/*you can write here*/); - not implemented yet
- break;
- case 4:
- //f4(/*you can write here*/); - not implemented yet
- break;
- /*you can write here*/
- }
- };
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement