Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. bool saveStats(const string& wy, int histogram[], const int N, const string pliki[], int srednie[], const int P)
  8. {
  9.     ofstream plik_wyj;
  10.     plik_wyj.open(wy);
  11.     if (!plik_wyj.is_open())
  12.         return false;
  13.     for (int i = 0; i < N; i++)
  14.     {
  15.         if (histogram[i] != 0)
  16.         {
  17.             plik_wyj << i << " " << histogram[i] << std::endl;
  18.         }
  19.     }
  20.     bool not_finish = true;
  21.     int i = 0;
  22.     int lowest_i = -1;
  23.     float lowest_srednia = srednie[0];
  24.     string dupa = "wtf";
  25.     while (not_finish)
  26.     {
  27.         for (int j = 0; j < P; j++)
  28.         {
  29.             if ((srednie[i] != -1.0f) && (srednie[i] < lowest_srednia))
  30.             {
  31.                 lowest_srednia = srednie[i];
  32.                 lowest_i = i;
  33.             }
  34.         }
  35.        
  36.         plik_wyj << pliki[lowest_i] << " " << srednie[lowest_i] << std::endl;
  37.         srednie[lowest_i] = -1.0f;
  38.         lowest_i = -1;
  39.         i++;
  40.         if (i == P)
  41.         {
  42.             not_finish = false;
  43.         }
  44.     }
  45.     plik_wyj.close();
  46.     return true;
  47. }
  48. bool stat(const string pliki[], const int P, const string& wy, const int N)
  49. {
  50.     ifstream plik;
  51.     int histogram[N] = { 0 };
  52.     float srednie[P] = { 0.0f };
  53.  
  54.     char bufor[sizeof(int)];
  55.  
  56.     for (int i = 0; i < P; i++)
  57.     {
  58.         plik.open(pliki[i], ios::binary);
  59.         if (!plik.is_open())
  60.             return false;
  61.         int value;
  62.         int ilosc_probek = 0;
  63.         while (!plik.eof())
  64.         {
  65.             plik.read(bufor, sizeof(int));
  66.             value = (int)bufor;
  67.             histogram[value]++;
  68.             ilosc_probek++;
  69.             srednie[i] += value;
  70.         }
  71.         plik.close();
  72.         srednie[i] /= ilosc_probek;
  73.     }
  74.  
  75.     return saveStats(wy, histogram, N);
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement