Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <windows.h>
- #include <time.h>
- #include <cstdlib>
- #include <bits/stdc++.h>
- using namespace std;
- int Check(int num_R[],int num_G[]) //對獎
- {
- int n = 0,s = 0;
- for(int i = 0;i<6;i++)
- {
- for(int j = 0;j<7;j++)
- {
- if(num_G[i] == num_R[j])
- {
- if(j == 6)
- s++;
- else
- n++;
- }
- }
- }
- if(n == 6)
- {
- cout<<"恭喜獲得頭獎!!!"<<endl;
- return 45637139;
- }
- else if(n == 5 && s == 1)
- {
- cout<<"恭喜獲得二獎!!!"<<endl;
- return 3617577;
- }
- else if(n == 5)
- {
- cout<<"恭喜獲得三獎!!!"<<endl;
- return 49319;
- }
- else if(n == 4 && s == 1)
- {
- cout<<"恭喜獲得四獎!!!"<<endl;
- return 15852;
- }
- else if(n == 4)
- {
- cout<<"恭喜獲得五獎!!!"<<endl;
- return 2000;
- }
- else if(n == 3 && s == 1)
- {
- cout<<"恭喜獲得六獎!!!"<<endl;
- return 1000;
- }
- else if(n == 2 && s == 1)
- {
- cout<<"恭喜獲得七獎!!!"<<endl;
- return 400;
- }
- else if(n == 3)
- {
- cout<<"恭喜獲得普獎!!!"<<endl;
- return 400;
- }
- else
- {
- cout<<"沒中"<<endl;
- return 0;
- }
- }
- void Guess(int num_G[])
- {
- int rand_num[49];
- for(int i = 0;i<49;i++)
- rand_num[i] = i+1;
- //shuffle
- for(int i = 0;i<10000;i++)
- swap(rand_num[rand()%49],rand_num[rand()%49]);
- cout<<"電腦選號: ";
- for(int i = 0;i<6;i++)
- {
- num_G[i] = rand_num[i];
- Sleep(2000);
- cout<<num_G[i]<<" ";
- }
- cout<<endl;
- }
- void Input_R(int num_R[])
- {
- cout<<"請輸入上期號碼"<<endl;
- for(int i = 0;i<7;i++)
- {
- if(i == 6)
- cout<<"請輸入特別號: ";
- else
- cout<<"請輸入第"<<i+1<<"個號碼: ";
- cin>>num_R[i];
- }
- }
- void Print_R(int num_R[])
- {
- cout<<"=====上期號碼====="<<endl;
- cout<<"獎號: ";
- for(int i = 0;i<7;i++)
- {
- if(i == 6)
- cout<<"特別號: ";
- cout<<num_R[i]<<" ";
- }
- cout<<endl;
- }
- int main()
- {
- srand(time(NULL));
- int num_R[7],num_G[6];
- cout<<"=====大樂透對獎系統====="<<endl;
- Input_R(num_R);//指示user輸入上期號碼
- system("cls"); // 清空畫面
- Print_R(num_R);
- Guess(num_G);
- Check(num_R,num_G);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement