Advertisement
Guest User

Untitled

a guest
May 1st, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. // pliki.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include<iostream>
  5. #include<fstream>
  6. #include<sstream>
  7. #include<Windows.h>
  8. #include<stdlib.h>
  9. #include<time.h>
  10.  
  11.  
  12. #define SIZET 100000
  13.  
  14. using namespace std;
  15.  
  16. int random()
  17. {
  18.     int i;
  19.     i = (rand() % 11) + 0;
  20.     return i;
  21. }
  22. void powturzenia()
  23. {
  24.     ofstream plk("powtorzenia.txt");
  25.     plk << " ";
  26.     plk.close();
  27. }
  28. void ilosc()
  29. {
  30.     ofstream plk("pzrzedu.txt");
  31.     plk << " ";
  32.     plk.close();
  33. }
  34. int main()
  35. {
  36.     srand(time(NULL));
  37.     int r[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  38.     powturzenia();
  39.     ilosc();
  40.     for (int i = 1; i <= 10; i++)
  41.     {
  42.         stringstream nazwa;
  43.         nazwa << i << ".txt";
  44.         ofstream plk(nazwa.str());
  45.         for (int j = 1; j <= SIZET; j++)
  46.         {
  47.             int c = random();
  48.             stringstream numery;
  49.             numery << c << " ";
  50.             plk << numery.str();
  51.         }
  52.         plk.close();
  53.     }
  54.  
  55.     for (int i = 1; i <= 10; i++)
  56.     {
  57.         int am[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  58.         stringstream nazwa;
  59.         nazwa << i << ".txt";
  60.         ifstream we(nazwa.str());
  61.         while (!we.eof())
  62.         {
  63.             int numery, a;
  64.             we >> numery;
  65.             r[numery] += 1;
  66.             am[numery] += 1;
  67.         }
  68.  
  69.         ofstream plk("powtorzenia.txt", ios::app);
  70.         plk << endl;
  71.         plk << "w " << i << " pliku:" << endl;
  72.         for (int j = 0; j <= 10; j++)
  73.         {
  74.             plk << "liczba " << j << " powtorzyla sie " << am[j] << " razy" << endl;
  75.         }
  76.         we.close();
  77.     }
  78.  
  79.     ofstream plk("powtorzenia.txt", ios::app);
  80.     plk << endl;
  81.     for (int i = 0; i <= 10; i++)
  82.     {
  83.  
  84.         plk << "liczba " << i << " pojawila sie " << r[i] << " razy\n";
  85.     }
  86.     plk.close();
  87.  
  88.     for (int i = 1; i <= 10; i++)
  89.     {
  90.         int tab[SIZET];
  91.         int re[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  92.         stringstream nazwa;
  93.         nazwa << i << ".txt";
  94.         ifstream we(nazwa.str());
  95.  
  96.         for (int j = 0; j<SIZET; j++)
  97.         {
  98.             we >> tab[j];
  99.         //  cout << tab[j] << " ";
  100.         }                          
  101.     //  cout << endl;
  102.  
  103.         int licznik = 0, test = 12;
  104.         for (int k = 0; k <= SIZET; k++)
  105.         {
  106.             if (tab[k] == test && licznik>re[tab[k]])
  107.             {
  108.                 licznik += 1;
  109.             }
  110.             else if (tab[k] == test && licznik <= re[tab[k]])
  111.             {
  112.                 licznik += 1;
  113.                 re[tab[k]] = licznik;
  114.             }
  115.             else
  116.             licznik = 0;
  117.             test = tab[k];
  118.  
  119.         }
  120.         ofstream plk("pzrzedu.txt", ios::app);
  121.         plk << "w pliku " << i << endl;
  122.         for (int l = 0; l <= 10; l++)
  123.         {
  124.             plk << "Liczba " << l << " powtorzyla sie z rzedu " << re[l] << " razy" << endl;
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement