#include <iostream> // cin, cout
#include <iomanip> // setprecision, fixed
#include <cstdlib> // rand, srand
#include <ctime> // time
using namespace std;
int dem_trung(const int a[], const int b[]);
void sinh_so_ngau_nhien(int ve[]);
long long tien_thuong(int x);
void mo_phong(int N, const int kq[]);
int main() {
srand(time(0));
int N;
cout << "Nhap so luong ve can mo phong: ";
cin >> N;
int kq[6];
cout << "Nhap 6 so trung thuong (1..45):\n";
for (int i = 0; i < 6; i++) {
cout << "So thu " << i + 1 << ": ";
cin >> kq[i];
}
mo_phong(N, kq);
return 0;
}
// Đếm số trùng giữa hai vé
int dem_trung(const int a[], const int b[]) {
int cnt = 0;
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
if (a[i] == b[j]) cnt++;
}
}
return cnt;
}
// Sinh 6 số ngẫu nhiên từ 1..45, không trùng
void sinh_so_ngau_nhien(int ve[]) {
int used[46] = {0};
int dem = 0;
while (dem < 6) {
int x = rand() % 45 + 1;
if (!used[x]) {
used[x] = 1;
ve[dem++] = x;
}
}
}
// Trả về tiền thưởng theo số trùng
long long tien_thuong(int x) {
if (x == 3) return 30000;
if (x == 4) return 300000;
if (x == 5) return 10000000;
if (x == 6) return 120000000;
return 0;
}
// Mô phỏng N vé, in ra từng vé và tính tỉ lệ hoàn vốn
void mo_phong(int N, const int kq[]) {
long long gia_ve = 10000;
long long tong_tien = gia_ve * N;
long long tien_thu = 0;
cout << "Dang mo phong " << N << " ve...\n";
for (int i = 0; i < N; i++) {
int ve[6];
sinh_so_ngau_nhien(ve);
int so_trung = dem_trung(ve, kq);
long long tienThuong = tien_thuong(so_trung);
tien_thu += tienThuong;
// In ra vé và kết quả
cout << "Ve " << i + 1 << ": ";
for (int j = 0; j < 6; j++) cout << ve[j] << " ";
cout << "| So trung: " << so_trung;
cout << " | Tien thuong: " << tienThuong << "\n";
}
double ty_le = (double)tien_thu / tong_tien * 100;
cout << fixed << setprecision(6) << "Ty le hoan von: " << ty_le << "%\n";
}