-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path고퀄복권.cpp
80 lines (67 loc) · 1.24 KB
/
고퀄복권.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct {
int numbers[5][6];
} Lottery;
void sort(int* key) {
int temp = 0;
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 6; j++) {
if (key[i] > key[j]) {
temp = key[i];
key[i] = key[j];
key[j] = temp;
}
}
}
}
void prt(int* key) {
printf("{");
for (int i = 0; i < 6; i++) {
printf("%2d", key[i]);
if (i < 5) {
printf(", ");
}
}
printf("}\n");
}
//중복된 값이 없는 6개의 값으로 대체된 배열
void check(int* key) {
key[0] = (rand() % 45) + 1;
for (int j = 1; j < 6; j++) {
haha:
key[j] = (rand() % 45) + 1;
for (int k = 0; k < j; k++) {
if (key[j] == key[k]) {
key[j] = (rand() % 45) + 1;
goto haha;
}
}
}
}
void printPaper(Lottery paper) {
for (int i = 0; i < 5; i++) {
prt(paper.numbers[i]);
}
}
int main() {
srand(time(NULL));
int l = 0;
printf("몇장 사시겠습니까? : ");
scanf_s("%d", &l);
for (int m = 0; m < l; m++) {
Lottery paper;
for (int n = 0; n < 5; n++) {
int key[6] = { 0,0,0,0,0,0 }; // 추첨된 복권의 당첨숫자의 배열
check(key);
sort(key);
for (int i = 0; i < 6; i++) {
paper.numbers[n][i] = key[i];
}
}
printPaper(paper);
printf("\n\n");
}
}