Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // pliki.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- #include<fstream>
- #include<sstream>
- #include<Windows.h>
- #include<stdlib.h>
- #include<time.h>
- #define SIZET 100000
- using namespace std;
- int random()
- {
- int i;
- i = (rand() % 11) + 0;
- return i;
- }
- void powturzenia()
- {
- ofstream plk("powtorzenia.txt");
- plk << " ";
- plk.close();
- }
- void ilosc()
- {
- ofstream plk("pzrzedu.txt");
- plk << " ";
- plk.close();
- }
- int main()
- {
- srand(time(NULL));
- int r[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- powturzenia();
- ilosc();
- for (int i = 1; i <= 10; i++)
- {
- stringstream nazwa;
- nazwa << i << ".txt";
- ofstream plk(nazwa.str());
- for (int j = 1; j <= SIZET; j++)
- {
- int c = random();
- stringstream numery;
- numery << c << " ";
- plk << numery.str();
- }
- plk.close();
- }
- for (int i = 1; i <= 10; i++)
- {
- int am[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- stringstream nazwa;
- nazwa << i << ".txt";
- ifstream we(nazwa.str());
- while (!we.eof())
- {
- int numery, a;
- we >> numery;
- r[numery] += 1;
- am[numery] += 1;
- }
- ofstream plk("powtorzenia.txt", ios::app);
- plk << endl;
- plk << "w " << i << " pliku:" << endl;
- for (int j = 0; j <= 10; j++)
- {
- plk << "liczba " << j << " powtorzyla sie " << am[j] << " razy" << endl;
- }
- we.close();
- }
- ofstream plk("powtorzenia.txt", ios::app);
- plk << endl;
- for (int i = 0; i <= 10; i++)
- {
- plk << "liczba " << i << " pojawila sie " << r[i] << " razy\n";
- }
- plk.close();
- for (int i = 1; i <= 10; i++)
- {
- int tab[SIZET];
- int re[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- stringstream nazwa;
- nazwa << i << ".txt";
- ifstream we(nazwa.str());
- for (int j = 0; j<SIZET; j++)
- {
- we >> tab[j];
- // cout << tab[j] << " ";
- }
- // cout << endl;
- int licznik = 0, test = 12;
- for (int k = 0; k <= SIZET; k++)
- {
- if (tab[k] == test && licznik>re[tab[k]])
- {
- licznik += 1;
- }
- else if (tab[k] == test && licznik <= re[tab[k]])
- {
- licznik += 1;
- re[tab[k]] = licznik;
- }
- else
- licznik = 0;
- test = tab[k];
- }
- ofstream plk("pzrzedu.txt", ios::app);
- plk << "w pliku " << i << endl;
- for (int l = 0; l <= 10; l++)
- {
- plk << "Liczba " << l << " powtorzyla sie z rzedu " << re[l] << " razy" << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement