Advertisement
justinpuckett

Untitled

May 29th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4.  
  5. int path(int);
  6. void printHistogram(int[],int, int);
  7.  
  8. int main()
  9. {
  10.     //Number of balls; Number of slots
  11.     int NOB;
  12.     int NOS;
  13.    
  14.     const int size = 50;
  15.     int slots[size];
  16.  
  17.     memset(slots, 0, sizeof(slots));
  18.  
  19.     cout << "Enter the number of slots in the bean machine: ";
  20.     cin >> NOS;
  21.    
  22.     cout << "Enter the number of balls to drop: ";
  23.     cin >> NOB;
  24.    
  25.     for (int i = 0; i < NOB; i++)
  26.     {
  27.         slots[path(NOS)]++;
  28.     }
  29.  
  30.     printHistogram(slots, NOS, NOB);
  31.  
  32.  
  33.     return 0;
  34.  
  35. }
  36.  
  37. int path(const int NOS)
  38. {
  39.     int P = 0;
  40.  
  41.     for (int i = 1; i < NOS; i++)
  42.     {
  43.  
  44.         int direction = rand() % 2;
  45.  
  46.         if (direction == 1)
  47.         {
  48.             cout << "R";
  49.         }
  50.         else
  51.         {
  52.             cout << "L";
  53.             P++;
  54.         }
  55.     }
  56.     cout << endl;
  57.     return P;
  58. }
  59.  
  60. void printHistofram(int slots[],const int NOS, int NOB)
  61. {
  62.     char ball[NOS + 1];
  63.  
  64.     int maxSH = 0;
  65.  
  66.     for (int i = NOB; i > 0; i--)
  67.     {
  68.         for (int j = 0; j <= NOS; j++)
  69.         {
  70.             if (i == slots[j])
  71.             {
  72.                 ball[j] = 'O';
  73.                 slots[j]--;
  74.             }
  75.             else
  76.                 ball[j] = ' ';
  77.             cout << ball[j];
  78.         }
  79.         cout << endl;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement