Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int *yolo(int *tablicaIn, int n) {
- int x = -1;
- int p = -1;
- for (int i = 0;i < n;i++) {
- int tmpx = tablicaIn[i];
- int tmpp = 1;
- for (int j = i + 1;j < n;j++) {
- if (tmpx == tablicaIn[j])
- tmpp++;
- }
- if (tmpp > p){
- p = tmpp;
- x = tmpx;
- }
- else if (p == tmpp) {
- if (tmpx > x) {
- x = tmpx;
- }
- }
- }
- int* tablicaOut = (int*)malloc(n*sizeof(int));
- int k = 0;
- for (int i = 0;i < n;i++) {
- if (tablicaIn[i] < x) {
- tablicaOut[k] = tablicaIn[i];
- k++;
- }
- }
- for (int i = 0;i < n;i++) {
- if (tablicaIn[i] >= x) {
- tablicaOut[k] = tablicaIn[i];
- k++;
- }
- }
- return tablicaOut;
- }
- int main() {
- int tablicaIn[] = { 4,5,7,1,5,9,4,5,3,4 };
- int *wynik = yolo(tablicaIn, 10);
- for (int i = 0;i < 10;i++) {
- printf("%d ", wynik[i]);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment