SHARE
TWEET

Untitled

a guest Jun 15th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<stack>
  3. #include <time.h>
  4. #define LASTSECTOR 4
  5.  using std::cout;
  6.  using std::cin;
  7.  using std::endl;
  8.  using std::string;
  9. // using std::stack;
  10. class lottery{
  11.  private:
  12.   int pocket_pointer;
  13.   int lottery_dram[36];
  14.   int ends_of_sectors_array[5];
  15.   int user_namber[37] = {0};
  16.   std::stack <int> drop_bals_stak;
  17.  
  18.  public:
  19.  
  20.  void take_namber_from_key(){
  21.    cout << "Введите 5 чисел от 1 до 36 через пробел " << endl;
  22.    int counter = 0;
  23.    int number = 0;
  24.    while(counter < 5){
  25.     cin >> number;
  26.     if(number > 0 && number < 37){
  27.       //cout << number << " n";
  28.       if(user_namber[number] == 0){
  29.        user_namber[number] = 1;
  30.        counter++;
  31.       }
  32.       else{
  33.          cout << "Число уже было введено: " << number << endl;
  34.       }
  35.      }
  36.     else {
  37.      cout << "Вы ввели неправильное число: " << number << endl;
  38.     }
  39.    }
  40.  
  41.  
  42.    for(int counter = 1; counter < 37; counter++){
  43.     //cout << user_namber[counter] << " ";
  44.     if(user_namber[counter] == 1){
  45.       //cout << counter << " ";
  46.     }
  47.    }
  48.     //cout << endl;
  49.  }
  50.  void throw_balls(){
  51.   int temp;
  52.   int rand_index;
  53.   for(int counter = 0; counter <= 35; counter++){
  54.    lottery_dram[counter] = counter + 1;
  55.    }
  56.   for (int counter = 0; counter <= 35; counter++){
  57.    rand_index = rand()%36;
  58.    temp = lottery_dram[counter];
  59.    lottery_dram[counter] = lottery_dram[rand_index];
  60.    lottery_dram[rand_index] = temp;
  61.    }
  62.    ends_of_sectors_array[0] = 0;
  63.    ends_of_sectors_array[1] = 13;
  64.    ends_of_sectors_array[2] = 26;
  65.    ends_of_sectors_array[3] = 30;
  66.    ends_of_sectors_array[4] = 35;
  67.    pocket_pointer = 0;
  68.  
  69.   }
  70. void print_balls_from_drum(){
  71.   for(int counter = 0; counter <= 35; counter++){
  72.    cout << lottery_dram[counter] << " ";
  73.   }
  74.   cout << endl;
  75.     cout << "top ball" << drop_bals_stak.top() << endl;
  76.  
  77.   for(int counter = 1; counter <= 4; counter++){
  78.     cout << "sector: " << counter << " " << ends_of_sectors_array[counter] << endl;
  79.   }
  80.  }
  81.  void shuffle_balls_in_sector(int sector_number){
  82.   int start, end, temp, rand_namber;
  83. //  cout << "Sector shuffle: " << sector_number << " start " << endl;
  84.   //print_balls_from_drum();
  85.   switch(sector_number){
  86.   case 1:
  87.    start = 0;
  88.    end = ends_of_sectors_array[1];
  89.   break;
  90.   case 2:
  91.    start = ends_of_sectors_array[1] + 1;
  92.    end = ends_of_sectors_array[2];
  93.   break;
  94.   case 3:
  95.    start = ends_of_sectors_array[2] + 1;
  96.    end = ends_of_sectors_array[3];
  97.   break;
  98.   case 4:
  99.    start = ends_of_sectors_array[3] + 1;
  100.    end = ends_of_sectors_array[LASTSECTOR];
  101.   break;
  102.   }
  103.   for(int counter = start; counter <= end; counter++){
  104.    rand_namber = std::rand()%(end - start + 1);
  105.    //cout << "rand_namber: " << rand_namber<< endl;
  106.    temp = lottery_dram[counter];
  107.    lottery_dram[counter] = lottery_dram[rand_namber];
  108.    lottery_dram[rand_namber] = temp;
  109.   }
  110.   //cout << "Sector shuffle: " << sector_number << " start " << endl;
  111.   //print_balls_from_drum();
  112.   ball_jump_from_sector(sector_number);
  113.  }
  114.   void array_scrolling(){
  115.   for(int counter = get_balls_count() - 1; counter > 0; counter-- ){
  116.    lottery_dram[counter] = lottery_dram[counter-1];
  117.   }
  118.  }
  119.  void pocket_scrolling(){
  120.   if(pocket_pointer > 0){
  121.    pocket_pointer--;
  122.   }
  123.     else {
  124.    pocket_pointer = get_balls_count() - 1;
  125.   };
  126.   cout << pocket_pointer << "" << endl;
  127.  }
  128.  
  129.  void ball_jump_from_sector(int sector_namber){
  130.   if (std::rand()%2 == 0){
  131.     if (sector_namber < 4){
  132.       ends_of_sectors_array[sector_namber] --;
  133.     }
  134.     else{
  135.      array_scrolling();
  136.      ends_of_sectors_array[1]++;
  137.      ends_of_sectors_array[2]++;
  138.      ends_of_sectors_array[3]++;
  139.  
  140.     };
  141.    }
  142.   }
  143.  
  144.  void dram_rotate (){
  145.   shuffle_balls_in_sector(1);
  146.   shuffle_balls_in_sector(2);
  147.   shuffle_balls_in_sector(3);
  148.   shuffle_balls_in_sector(4);
  149.   pocket_scrolling();
  150.   drop_ball_to_pocet();
  151.   array_scrolling();
  152.  }
  153.  
  154.  void drop_ball_to_pocet(){
  155.   int sector_namber = 0;
  156.   if(pocket_pointer <= ends_of_sectors_array[1]){
  157.    sector_namber = 1;
  158.    }
  159.    else if(pocket_pointer <= ends_of_sectors_array[2]){
  160.       sector_namber = 2;
  161.     }
  162.     else if(pocket_pointer <= ends_of_sectors_array[3]){
  163.       sector_namber = 3;
  164.     }
  165.     else if(pocket_pointer <= ends_of_sectors_array[4]){
  166.       sector_namber = 4;
  167.     }
  168. //    cout << "ball_pocket_pointer_in_sector" << sector_namber << " sector_1_end" << ends_of_sectors_array[1] << " sector_2_end " << ends_of_sectors_array[2] << " sector_3_end" << ends_of_sectors_array[3] << " sector_4_end" << ends_of_sectors_array[4] << endl;
  169.     if(rand()%1 == 0){
  170.      drop_bals_stak.push(lottery_dram[pocket_pointer]);
  171. //     cout << drop_bals_stak.top() << " "; // << endl;
  172.  
  173.      for(int counter = pocket_pointer; counter < ends_of_sectors_array[4]; counter++){
  174.       lottery_dram[counter] = lottery_dram[counter + 1];
  175.  
  176.      }
  177.         lottery_dram[ends_of_sectors_array[4]];
  178.  
  179.      for (int counter = sector_namber; counter <= LASTSECTOR; counter++){
  180.       ends_of_sectors_array[counter]--;
  181.       }
  182.     }
  183.  }
  184.  
  185.  int get_balls_count(){
  186.   int balls_count;
  187.   balls_count = ends_of_sectors_array[4] + 1;
  188.   return(balls_count);
  189.  }
  190.  void check_user_result(){
  191.  
  192.  
  193.  }
  194.  
  195.  int get_dropped_balls_count(){
  196.   return(36 - get_balls_count());
  197.  }
  198. };
  199.  
  200. int main(){
  201.   std::srand(time(NULL));
  202.   std::rand();
  203.   lottery lot1;
  204.   lot1.take_namber_from_key();
  205. //  while(lot1.get_dropped_balls_count() < 5){
  206.     lot1.throw_balls();
  207.     //lot1.print_balls_from_drum();
  208.     lot1.dram_rotate();
  209.     lot1.dram_rotate();
  210.     lot1.dram_rotate();
  211. //  }
  212. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top