Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- bool saveStats(const string& wy, int histogram[], const int N, const string pliki[], int srednie[], const int P)
- {
- ofstream plik_wyj;
- plik_wyj.open(wy);
- if (!plik_wyj.is_open())
- return false;
- for (int i = 0; i < N; i++)
- {
- if (histogram[i] != 0)
- {
- plik_wyj << i << " " << histogram[i] << std::endl;
- }
- }
- bool not_finish = true;
- int i = 0;
- int lowest_i = -1;
- float lowest_srednia = srednie[0];
- string dupa = "wtf";
- while (not_finish)
- {
- for (int j = 0; j < P; j++)
- {
- if ((srednie[i] != -1.0f) && (srednie[i] < lowest_srednia))
- {
- lowest_srednia = srednie[i];
- lowest_i = i;
- }
- }
- plik_wyj << pliki[lowest_i] << " " << srednie[lowest_i] << std::endl;
- srednie[lowest_i] = -1.0f;
- lowest_i = -1;
- i++;
- if (i == P)
- {
- not_finish = false;
- }
- }
- plik_wyj.close();
- return true;
- }
- bool stat(const string pliki[], const int P, const string& wy, const int N)
- {
- ifstream plik;
- int histogram[N] = { 0 };
- float srednie[P] = { 0.0f };
- char bufor[sizeof(int)];
- for (int i = 0; i < P; i++)
- {
- plik.open(pliki[i], ios::binary);
- if (!plik.is_open())
- return false;
- int value;
- int ilosc_probek = 0;
- while (!plik.eof())
- {
- plik.read(bufor, sizeof(int));
- value = (int)bufor;
- histogram[value]++;
- ilosc_probek++;
- srednie[i] += value;
- }
- plik.close();
- srednie[i] /= ilosc_probek;
- }
- return saveStats(wy, histogram, N);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement