Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include<iostream>
  2. #include<ctime>
  3. #include<cstdlib>
  4. #include<windows.h>
  5. using namespace std;
  6.  
  7. int main() {
  8. srand(time(NULL));
  9. int index = 0;
  10. float rand01;
  11. const int wielkosc_stosu = 20;
  12. int id = 1000; //id dokumentu
  13. float p; //Prawdopodobienstwo polozenia dokumentu na stosie
  14. int wierzcholek = 0; // Wierzcholek stosu
  15. int x;
  16.  
  17. //Stwórz i wypełnij tablicę
  18. int stos[wielkosc_stosu];
  19. for (int i = 0; i < wielkosc_stosu-1; i++)
  20. {
  21. stos[i] = (rand() % 1000) + 1;
  22. }
  23.  
  24. cout << "Podaj prawdopodobienstwo (0.00 do 1.00): ";
  25. cin >> p;
  26. cout << endl;
  27.  
  28. do {
  29. rand01 = (rand() % 99);
  30. rand01 /= 100;
  31. cout << "Losowa: " << rand01 << endl;
  32. if (rand01 < p) {
  33. stos[wierzcholek] = id;
  34. cout << "Polozenie dokumentu o ID " << id << " na stosie. " << endl;
  35. }
  36. else {
  37. if (wierzcholek > 0) {
  38. x = stos[wierzcholek - 1];
  39. cout << "Pobranie dokumentu o ID " << x << " ze stosu. " << endl;
  40. cout << "Zwalnianie miejsca dokumentu o ID " << x << endl;
  41. stos[wierzcholek] == NULL; //Zwalnianie miejsca dokumentu
  42. }
  43. else {
  44. cout << "Na stosie nie ma dokumentu, ktory mozna pobrac. " << endl;
  45. }
  46. }
  47. cout << endl;
  48. wierzcholek++;
  49. id++;
  50. index++;
  51. Sleep(3000);
  52. } while (index != 19);
  53. system("pause");
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement