-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSizeRecommendation.java
More file actions
202 lines (184 loc) Β· 6.22 KB
/
SizeRecommendation.java
File metadata and controls
202 lines (184 loc) Β· 6.22 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package cote;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* π§© λ¬Έμ : μ¬μ΄μ¦ μΆμ² μμ€ν
*
* μλ₯ μΌνλͺ°μμλ λΈλλλ³λ‘ μλ‘ λ€λ₯Έ μ¬μ΄μ¦ κΈ°μ€μ μ¬μ©νλ€.
* κ³ κ°μ μ 체 μ 보λ₯Ό κΈ°λ°μΌλ‘, κ³ κ°μ΄ μνλ λΈλλμμ μ μ ν μ¬μ΄μ¦λ₯Ό μΆμ²νλ νλ‘κ·Έλ¨μ μμ±νλΌ.
*
* ------------------------------------------------------------
* β
κ·μΉ
*
* κ° λΈλλλ μ¬λ¬ κ°μ μ¬μ΄μ¦ μ 보λ₯Ό κ°μ§λ€.
* κ° μ¬μ΄μ¦λ λ€μ λ²μλ₯Ό κ°μ§λ€:
*
* - ν€ μ΅μ ~ ν€ μ΅λ
* - κ°μ΄λλ μ΅μ ~ κ°μ΄λλ μ΅λ
* - ν리λλ μ΅μ ~ ν리λλ μ΅λ
*
* κ³ κ°μ λ€μ μ 보λ₯Ό μ
λ ₯νλ€:
* - μνλ λΈλλλͺ
* - ν€
* - κ°μ΄λλ
* - ν리λλ
*
* ------------------------------------------------------------
* β
μΆλ ₯ κ·μΉ (κ³ κ° 1λͺ
λΉ 1μ€ μΆλ ₯)
*
* 1. κ³ κ°μ΄ μνλ λΈλλκ° μ‘΄μ¬νμ§ μμΌλ©΄
* β UNKNOWN
*
* 2. λΈλλλ μ‘΄μ¬νμ§λ§ λ§λ μ¬μ΄μ¦κ° μμΌλ©΄
* β λΈλλλͺ
,MISMATCH
*
* 3. λ§λ μ¬μ΄μ¦κ° μ‘΄μ¬νλ©΄
* β λΈλλλͺ
,μ¬μ΄μ¦λͺ
*
* β» μ¬λ¬ μ¬μ΄μ¦κ° 쑰건μ λ§μ‘±ν κ²½μ°,
* μ
λ ₯λ μμλλ‘ κ°μ₯ λ¨Όμ λμ¨ μ¬μ΄μ¦λ₯Ό μΆμ²νλ€.
* (μ¬μ΄μ¦λ₯Ό μμ μμλλ‘ μ
λ ₯νλ©΄ μλμΌλ‘ κ°μ₯ μμ μ¬μ΄μ¦κ° μ νλλ€.)
*
* ------------------------------------------------------------
* β
μ
λ ₯ νμ
*
* B,C // λΈλλ κ°μ, κ³ κ° μ
*
* λΈλλλͺ
,μ¬μ΄μ¦κ°μ
* μ¬μ΄μ¦λͺ
,ν€μ΅μ,ν€μ΅λ,κ°μ΄μ΅μ,κ°μ΄μ΅λ,ν리μ΅μ,ν리μ΅λ
* ...
* (λΈλλ μ λ§νΌ λ°λ³΅)
*
* λΈλλλͺ
,ν€,κ°μ΄λλ ,ν리λλ
* ...
* (κ³ κ° μ λ§νΌ λ°λ³΅)
*
* ------------------------------------------------------------
* β
μ
λ ₯ μμ
*
* 2,5
* Nike,2
* S,160,175,80,95,24,30
* M,165,180,85,100,26,32
* Adidas,2
* SM,160,170,80,90,24,26
* XL,175,190,100,105,32,40
* Musinsa,163,85,24
* Nike,170,90,28
* Adidas,163,85,24
* Adidas,180,85,24
* Nike,173,85,27
*
* ------------------------------------------------------------
* β
μΆλ ₯ μμ
*
* Musinsa,UNKNOWN
* Nike,S
* Adidas,SM
* Adidas,MISMATCH
* Nike,S
*
* ------------------------------------------------------------
* β
μΆλ ₯ μ€λͺ
*
* 1. Musinsa,163,85,24 β λΈλλ μμ β Musinsa,UNKNOWN
* 2. Nike,170,90,28 β Sμ M λͺ¨λ λ§€μΉ, μ
λ ₯ μμμ 첫 λ²μ§ΈμΈ S μ ν β Nike,S
* 3. Adidas,163,85,24 β SMλ§ λ§€μΉ β Adidas,SM
* 4. Adidas,180,85,24 β λ§€μΉ μμ β Adidas,MISMATCH
* 5. Nike,173,85,27 β Sλ§ λ§€μΉ β Nike,S
*
* ------------------------------------------------------------
* β
ν΅μ¬ μλ£κ΅¬μ‘°
*
* Map<λΈλλλͺ
, List<SizeInfo>>
*
* λΈλλλ§λ€ μ¬λ¬ μ¬μ΄μ¦λ₯Ό κ°μ§λ―λ‘ Listλ‘ κ΄λ¦¬νλ€.
* κ³ κ° μμ² μ ν΄λΉ λΈλλμ μ¬μ΄μ¦ 리μ€νΈλ₯Ό μννλ©° 쑰건μ λ§λ μ¬μ΄μ¦λ₯Ό μ°Ύλλ€.
*/
public class SizeRecommendation {
static class SizeInfo {
String sizeName;
int heightMin, heightMax;
int chestMin, chestMax;
int waistMin, waistMax;
SizeInfo(String sizeName, int heightMin, int heightMax,
int chestMin, int chestMax, int waistMin, int waistMax) {
this.sizeName = sizeName;
this.heightMin = heightMin;
this.heightMax = heightMax;
this.chestMin = chestMin;
this.chestMax = chestMax;
this.waistMin = waistMin;
this.waistMax = waistMax;
}
boolean matches(int height, int chest, int waist) {
return height >= heightMin && height <= heightMax &&
chest >= chestMin && chest <= chestMax &&
waist >= waistMin && waist <= waistMax;
}
}
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// λΈλλ κ°μ, κ³ κ° μ μ
λ ₯
String[] firstLine = br.readLine().split(",");
int brandCount = Integer.parseInt(firstLine[0]);
int customerCount = Integer.parseInt(firstLine[1]);
// λΈλλλ³ μ¬μ΄μ¦ μ 보 μ μ₯
Map<String, List<SizeInfo>> brandSizes = new HashMap<>();
// λΈλλ μ 보 μ
λ ₯
for (int i = 0; i <brandCount; i++) {
String[] brandInfo = br.readLine().split(",");
String brandName = brandInfo[0];
int sizeCount = Integer.parseInt(brandInfo[1]);
List<SizeInfo> sizes = new ArrayList<>();
// κ° λΈλλμ μ¬μ΄μ¦ μ 보 μ
λ ₯
for (int j = 0; j < sizeCount; j++) {
String[] sizeData = br.readLine().split(",");
String sizeName = sizeData[0];
int heightMin = Integer.parseInt(sizeData[1]);
int heightMax = Integer.parseInt(sizeData[2]);
int chestMin = Integer.parseInt(sizeData[3]);
int chestMax = Integer.parseInt(sizeData[4]);
int waistMin = Integer.parseInt(sizeData[5]);
int waistMax = Integer.parseInt(sizeData[6]);
sizes.add(new SizeInfo(sizeName, heightMin, heightMax,
chestMin, chestMax, waistMin, waistMax));
}
brandSizes.put(brandName, sizes);
}
// κ³ κ°λ³ μ¬μ΄μ¦ μΆμ²
for (int i = 0; i < customerCount; i++) {
String[] customerInfo = br.readLine().split(",");
String requestedBrand = customerInfo[0];
int height = Integer.parseInt(customerInfo[1]);
int chest = Integer.parseInt(customerInfo[2]);
int waist = Integer.parseInt(customerInfo[3]);
// λΈλλκ° μλ κ²½μ°
if (!brandSizes.containsKey(requestedBrand)) {
System.out.println(requestedBrand + ",UNKNOWN");
continue;
}
// λ§λ μ¬μ΄μ¦ μ°ΎκΈ°
List<SizeInfo> sizes = brandSizes.get(requestedBrand);
String recommendedSize = null;
// μ¬λ¬ μ¬μ΄μ¦κ° λ§€μΉλλ©΄ μ
λ ₯ μμλλ‘ μ²« λ²μ§Έ μ¬μ΄μ¦ μ ν
// (μ¬μ΄μ¦λ₯Ό μμ μμλλ‘ μ
λ ₯νλ€λ©΄ μλμΌλ‘ κ°μ₯ μμ μ¬μ΄μ¦κ° μ νλ¨)
for (SizeInfo size : sizes) {
if (size.matches(height, chest, waist)) {
recommendedSize = size.sizeName;
break; // 첫 λ²μ§Έ λ§€μΉ μ¬μ΄μ¦λ₯Ό μ°ΎμΌλ©΄ μ¦μ μ’
λ£
}
}
// κ²°κ³Ό μΆλ ₯
if (recommendedSize != null) {
System.out.println(requestedBrand + "," + recommendedSize);
} else {
System.out.println(requestedBrand + ",MISMATCH");
}
}
}
}