Advertisement
luluinstalock

Untitled

Feb 11th, 2016
1,597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int *yolo(int *tablicaIn, int n) {
  5.     int x = -1;
  6.     int p = -1;
  7.    
  8.     for (int i = 0;i < n;i++) {
  9.         int tmpx = tablicaIn[i];
  10.         int tmpp = 1;
  11.         for (int j = i + 1;j < n;j++) {
  12.             if (tmpx == tablicaIn[j])
  13.                 tmpp++;
  14.         }
  15.         if (tmpp > p){
  16.             p = tmpp;
  17.             x = tmpx;
  18.         }
  19.         else if (p == tmpp) {
  20.             if (tmpx > x) {
  21.                 x = tmpx;
  22.             }
  23.         }
  24.     }
  25.     int* tablicaOut = (int*)malloc(n*sizeof(int));
  26.     int k = 0;
  27.     for (int i = 0;i < n;i++) {
  28.         if (tablicaIn[i] < x) {
  29.             tablicaOut[k] = tablicaIn[i];
  30.             k++;
  31.         }
  32.     }
  33.     for (int i = 0;i < n;i++) {
  34.         if (tablicaIn[i] >= x) {
  35.             tablicaOut[k] = tablicaIn[i];
  36.             k++;
  37.         }
  38.     }
  39.  
  40.     return tablicaOut;
  41. }
  42.  
  43. int main() {
  44.     int tablicaIn[] = { 4,5,7,1,5,9,4,5,3,4 };
  45.  
  46.     int *wynik = yolo(tablicaIn, 10);
  47.     for (int i = 0;i < 10;i++) {
  48.         printf("%d ", wynik[i]);
  49.     }
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement