Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <time.h>
  5. #include <fstream>
  6. #include <string>
  7. #include <sstream>
  8.  
  9. int i, k;
  10. using namespace std;
  11. string filename, linia, nazwa;
  12. fstream plik, wynik;
  13. int tab[100];
  14. int Liczba_Powtorzen(int tab1[100], int j)
  15. {
  16. srand(time(NULL));
  17. int licznik = 0;
  18. for (int k = 0; k < 100; k++)
  19. {
  20. if ((j + 1) == tab1[k])
  21. licznik = licznik + 1;
  22. }
  23. return licznik;
  24. }
  25.  
  26. int main()
  27. {
  28.  
  29. for ( i = 1; i < 11; i++)
  30. {
  31. stringstream a;
  32. a << i;
  33. filename = "file_" + a.str();
  34. filename += ".txt";
  35.  
  36. cout << filename << endl;
  37.  
  38. plik.open(filename.c_str(), ios::out);
  39. for (int j = 0; j < 100; j++)
  40. {
  41. tab[i] = rand() % 10 + 1;
  42. plik << tab[i] << endl;
  43. }
  44. plik.close();
  45. }
  46. wynik.open("plik_wynikowy.txt", ios::out);
  47. for (k = 1; k < 11; k++)
  48. {
  49. stringstream b;
  50. b << k;
  51. nazwa = "file_" + b.str();
  52. wynik << nazwa << endl;
  53. plik.open(filename.c_str(), ios::in);
  54. int tabs[10], tabr[10];
  55. for (int z = 0; z < 100; z++)
  56. {
  57. getline(plik, linia);
  58.  
  59. int tabzm[100], its;
  60.  
  61. its = atoi(linia.c_str());
  62. tabzm[z] = its;
  63. for (int x = 0; x < 10; x++)
  64. {
  65. tabs[x] = Liczba_Powtorzen(tabzm,x);
  66. }
  67. }
  68. for (int d = 0; d < 10; d++)
  69. {
  70. wynik << "Liczba " << d + 1 << " wystapila w pliku " << tabs[d] << endl;
  71. }
  72. plik.close();
  73. }
  74. wynik.close();
  75.  
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement