Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void printBin(int val); //inny sposob
- int maxElement(int t[], unsigned int size);
- bool allElementsUnique(int t[], unsigned int size);
- int nr0f0ccurrences(int t[], unsigned int size, int val);
- int dominant(int t[], unsigned int size);
- int main()
- {
- int value = 45;
- cout << value << " == ";
- printBin(value);
- cout << endl;
- const unsigned int size1 = 14u;
- const unsigned int size2 = 10u;
- int t1[size1] = { 1, 1, 3, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8 };
- int t2[size2] = { 0, 5, 7, 2, 4, 1, 6, 3, 8, 9};
- cout << maxElement(t1, size1) << endl;
- cout << maxElement(t2, size2) << endl;
- cout <<boolalpha<< allElementsUnique(t1, size1) << endl;
- cout <<boolalpha << allElementsUnique(t2, size2) << endl;
- cout << nr0f0ccurrences(t1, size1, 2) << endl;
- cout << nr0f0ccurrences(t1, size1, 5) << endl;
- cout << nr0f0ccurrences(t1, size1, 7) << endl;
- cout << nr0f0ccurrences(t2, size2, 4) << endl;
- cout << dominant(t1, size1) << endl;
- cout << dominant(t2, size2) << endl;
- system("pause");
- return 0;
- }
- void printBin(int val)
- {
- int tab[6] = { 0, 0, 0, 0, 0, 0 };
- for (int i = 0; i < 6; i++)
- {
- tab[i] = val % 2;
- if (val % 2 == 1)
- {
- val = (val - 1) / 2;
- }
- else
- {
- val = val / 2;
- }
- }
- for (int i = 5; i >= 0; i--)
- {
- cout << tab[i];
- }
- }
- int maxElement(int t[], unsigned int size)
- {
- int a = 0;
- for (int i = 0; i < size; i++)
- {
- if (t[i]>a)
- {
- a = t[i];
- }
- }
- return a;
- }
- bool allElementsUnique(int t[], unsigned int size)
- {
- int x, a;
- for (int i = 0; i < size; i++)
- {
- x = t[i];
- a = 0;
- for (int j = 0; j < size; j++)
- {
- if (t[j] == x)
- {
- a++;
- }
- }
- if (a > 1)
- {
- return false;
- }
- }
- return true;
- }
- int nr0f0ccurrences(int t[], unsigned int size, int val)
- {
- int powtorzenia = 0;
- for (int i = 1; i < size; i++)
- {
- if (t[i] == val)
- powtorzenia++;
- }
- if (powtorzenia == 0)
- {
- return -1;
- }
- else
- {
- return powtorzenia;
- }
- }
- int dominant(int t[], unsigned int size)
- {
- int counter = 0;
- int dominant;
- int max = 0;
- for (int i = 0; i < size; i++)
- {
- for (int j = 0; j < size; j++)
- {
- if (t[i] == t[j]) counter++;
- }
- if (counter>max)
- {
- max = counter;
- dominant = t[i];
- }
- counter = 0;
- }
- return dominant;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement