Advertisement
penguin88428

lottery

Nov 16th, 2022 (edited)
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <windows.h>
  4. #include <time.h>
  5. #include <cstdlib>
  6. #include <bits/stdc++.h>
  7. using namespace std;
  8. int Check(int num_R[],int num_G[]) //對獎
  9. {
  10.     int n = 0,s = 0;
  11.     for(int i = 0;i<6;i++)
  12.     {
  13.         for(int j = 0;j<7;j++)
  14.         {
  15.             if(num_G[i] == num_R[j])
  16.             {
  17.                 if(j == 6)
  18.                     s++;
  19.                 else
  20.                     n++;
  21.             }
  22.         }
  23.     }
  24.     if(n == 6)
  25.     {
  26.         cout<<"恭喜獲得頭獎!!!"<<endl;
  27.         return 45637139;
  28.     }
  29.     else if(n == 5 && s == 1)
  30.     {
  31.         cout<<"恭喜獲得二獎!!!"<<endl;
  32.         return 3617577;
  33.     }
  34.     else if(n == 5)
  35.     {
  36.         cout<<"恭喜獲得三獎!!!"<<endl;
  37.         return 49319;
  38.     }  
  39.     else if(n == 4 && s == 1)
  40.     {
  41.         cout<<"恭喜獲得四獎!!!"<<endl;
  42.         return 15852;
  43.     }
  44.     else if(n == 4)
  45.     {
  46.         cout<<"恭喜獲得五獎!!!"<<endl;
  47.         return 2000;
  48.     }
  49.     else if(n == 3 && s == 1)
  50.     {
  51.         cout<<"恭喜獲得六獎!!!"<<endl;
  52.         return 1000;
  53.     }
  54.     else if(n == 2 && s == 1)
  55.     {
  56.         cout<<"恭喜獲得七獎!!!"<<endl;
  57.         return 400;
  58.     }  
  59.     else if(n == 3)
  60.     {
  61.         cout<<"恭喜獲得普獎!!!"<<endl;
  62.         return 400;
  63.     }
  64.     else
  65.     {
  66.         cout<<"沒中"<<endl;
  67.         return 0;
  68.     }
  69.        
  70. }
  71. void Guess(int num_G[])
  72. {
  73.     int rand_num[49];
  74.     for(int i = 0;i<49;i++)
  75.         rand_num[i] = i+1;
  76.     //shuffle
  77.     for(int i = 0;i<10000;i++)
  78.         swap(rand_num[rand()%49],rand_num[rand()%49]);
  79.     cout<<"電腦選號: ";
  80.     for(int i = 0;i<6;i++)
  81.     {
  82.         num_G[i] = rand_num[i];
  83.         Sleep(2000);
  84.         cout<<num_G[i]<<" ";
  85.     }
  86.     cout<<endl;
  87.        
  88.    
  89. }
  90. void Input_R(int num_R[])
  91. {
  92.     cout<<"請輸入上期號碼"<<endl;
  93.     for(int i = 0;i<7;i++)
  94.     {
  95.         if(i == 6)
  96.             cout<<"請輸入特別號: ";
  97.         else
  98.             cout<<"請輸入第"<<i+1<<"個號碼: ";
  99.         cin>>num_R[i];
  100.     }
  101. }
  102. void Print_R(int num_R[])
  103. {
  104.     cout<<"=====上期號碼====="<<endl;
  105.     cout<<"獎號: ";
  106.     for(int i = 0;i<7;i++)
  107.     {
  108.         if(i == 6)
  109.             cout<<"特別號: ";
  110.         cout<<num_R[i]<<" ";
  111.     }
  112.     cout<<endl;
  113. }
  114.  
  115. int main()
  116. {
  117.     srand(time(NULL));
  118.     int num_R[7],num_G[6];
  119.     cout<<"=====大樂透對獎系統====="<<endl;
  120.     Input_R(num_R);//指示user輸入上期號碼
  121.     system("cls"); // 清空畫面
  122.     Print_R(num_R);
  123.     Guess(num_G);
  124.     Check(num_R,num_G);
  125.     return 0;
  126. }
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement