-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc003.c
More file actions
126 lines (99 loc) · 3.17 KB
/
c003.c
File metadata and controls
126 lines (99 loc) · 3.17 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int findRoom(int persons[5]);
void printReport(char mn[10][20], int mr[10], int mc, char wn[10][20], int wr[10], int wc);
int main() {
system("chcp 65001>nul");
char mNames[10][20];
int mRoom[10];
int mCount = 0;
int mPersons[5] = {0};
char wNames[10][20];
int wRoom[10];
int wCount = 0;
int wPersons[5] = {0};
int menu;
int roomNum;
srand(time(NULL));
printf("===========================================\n");
printf("생활관 호실 배정 프로그램\n");
printf("===========================================\n");
while (1) {
printf("메뉴 : 1.남학생 등록 2.여학생 등록 0.종료 > ");
scanf("%d", &menu);
if (menu == 0) {
break;
}
else if (menu == 1) {
if (mCount >= 10) {
printf("남학생 등록 인원 초과입니다!\n");
continue;
}
printf("학생 이름은? > ");
scanf("%s", mNames[mCount]);
roomNum = findRoom(mPersons);
mRoom[mCount] = roomNum;
mPersons[roomNum - 1]++;
mCount++;
printf("%s 학생 10%d호실 배정되었습니다.\n", mNames[mCount-1], roomNum);
}
else if (menu == 2) {
if (wCount >= 10) {
printf("여학생 등록 인원 초과입니다!\n");
continue;
}
printf("학생 이름은? > ");
scanf("%s", wNames[wCount]);
roomNum = findRoom(wPersons);
wRoom[wCount] = roomNum;
wPersons[roomNum - 1]++;
wCount++;
printf("%s 학생 20%d호실 배정되었습니다.\n", wNames[wCount-1], roomNum);
}
}
printf("===========================================\n");
printf("생활관 호실 배정 결과는 다음과 같습니다.\n");
printf("===========================================\n");
printReport(mNames, mRoom, mCount, wNames, wRoom, wCount);
return 0;
}
int findRoom(int persons[5]) {
int r;
while (1) {
r = rand() % 5;
if (persons[r] < 2) {
return r + 1;
}
}
}
void printReport(char mn[10][20], int mr[10], int mc, char wn[10][20], int wr[10], int wc) {
int i, j;
printf("남학생 명단 (%d명)\n", mc);
for (i = 0; i < mc; i++) {
printf("%d. %s [10%d호]\n", i + 1, mn[i], mr[i]);
}
printf("\n여학생 명단 (%d명)\n", wc);
for (i = 0; i < wc; i++) {
printf("%d. %s [20%d호]\n", i + 1, wn[i], wr[i]);
}
printf("\n호실별 배정 명단\n");
for (i = 1; i <= 5; i++) {
printf("10%d호 : ", i);
for (j = 0; j < mc; j++) {
if (mr[j] == i) {
printf("%s ", mn[j]);
}
}
printf("\n");
}
for (i = 1; i <= 5; i++) {
printf("20%d호 : ", i);
for (j = 0; j < wc; j++) {
if (wr[j] == i) {
printf("%s ", wn[j]);
}
}
printf("\n");
}
}