Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1fb6f9b

Browse files
committed
Lv2_메뉴리뉴얼
1 parent 4f1ab6c commit 1fb6f9b

File tree

4 files changed

+88
-8
lines changed

4 files changed

+88
-8
lines changed

‎Programmers/Lv1/Lv1_신규아이디추천.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <string>
1+
#include <string>
22
#include <vector>
33
#include <iostream>
44
using namespace std;
@@ -7,35 +7,35 @@ string solution(string new_id) {
77
string answer = "";
88

99
for (int i = 0; i < new_id.length(); ++i) {
10-
// 1?4퀎
10+
// 1단계
1111
new_id[i] = tolower(new_id[i]);
1212

13-
// 2?4퀎
13+
// 2단계
1414
if ((new_id[i] >= 48 && new_id[i] <= 57) || (new_id[i] >= 97 && new_id[i] <= 122) || new_id[i]==45 || new_id[i]==95)
1515
answer += new_id[i];
16-
else if (new_id[i] == 46) { // 3?4퀎
16+
else if (new_id[i] == 46) { // 3단계
1717
if(i==0 || (i>0 && answer[answer.length()-1] != 46))
1818
answer += new_id[i];
1919
}
2020
}
2121

22-
// 4?4퀎
22+
// 4단계
2323
if (answer[0] == 46)
2424
answer = answer.substr(1, answer.length() - 1);
2525
if (answer[answer.length() - 1] == 46)
2626
answer = answer.substr(0, answer.length() - 1);
2727

28-
// 5?4퀎
28+
// 5단계
2929
if (answer.length() == 0)
3030
answer += "a";
3131

32-
// 6?4퀎
32+
// 6단계
3333
if (answer.length() > 15)
3434
answer = answer.substr(0, 15);
3535
if (answer[answer.length() - 1] == 46)
3636
answer = answer.substr(0, answer.length() - 1);
3737

38-
// 7?4퀎
38+
// 7단계
3939
while (answer.length() < 3)
4040
answer += answer[answer.length()-1];
4141

‎Programmers/Lv2/Lv2_메뉴리뉴얼.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <string>
2+
#include <vector>
3+
#include <iostream>
4+
#include <map>
5+
#include <algorithm>
6+
using namespace std;
7+
8+
map<string, int> m;
9+
10+
void combination(string s, int len) {
11+
vector<bool> check(s.length(), true);
12+
for (int i = 0; i < len; ++i)
13+
check[i] = false;
14+
15+
do {
16+
string menu = "";
17+
for (int i = 0; i < s.length(); ++i) {
18+
if (!check[i])
19+
menu += s[i];
20+
}
21+
22+
if (m.count(menu) > 0)
23+
m[menu]++;
24+
else
25+
m.insert({ menu,1 });
26+
} while (next_permutation(check.begin(), check.end()));
27+
}
28+
29+
vector<string> solution(vector<string> orders, vector<int> course) {
30+
vector<string> answer;
31+
32+
for (auto a : orders) {
33+
for (auto b : course) {
34+
if (a.length() >= b) { // 시킨 메뉴갯수가 코스메뉴 갯수 이상이면?
35+
sort(a.begin(), a.end());
36+
combination(a, b);
37+
}
38+
}
39+
}
40+
for (auto b : course) { // 메뉴 갯수
41+
vector<pair<string, int>> ans;
42+
43+
for (auto a : m) { // 메뉴
44+
if (a.first.length() < b)
45+
continue;
46+
if (a.first.length() == b && a.second >= 2) {
47+
if(ans.size() == 0 || a.second == ans[0].second)
48+
ans.push_back(a);
49+
else if(ans.size()>0 && a.second > ans[0].second) {
50+
ans.clear();
51+
ans.push_back(a);
52+
}
53+
}
54+
}
55+
56+
for (auto c : ans)
57+
answer.push_back(c.first);
58+
}
59+
60+
sort(answer.begin(), answer.end());
61+
return answer;
62+
}
63+
64+
int main() {
65+
vector<string> orders = { "XYZ", "XWY", "WXA" };
66+
vector<int> course = { 2,3,4 };
67+
68+
vector<string> ans = solution(orders, course);
69+
70+
for (auto a : ans)
71+
cout << a << " ";
72+
73+
return 0;
74+
}

‎Programmers/Programmers.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@
220220
<ClCompile Include="Lv2\Lv2_멀쩡한사각형.cpp">
221221
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
222222
</ClCompile>
223+
<ClCompile Include="Lv2\Lv2_메뉴리뉴얼.cpp">
224+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
225+
</ClCompile>
223226
<ClCompile Include="Lv2\Lv2_소수만들기.cpp">
224227
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
225228
</ClCompile>

‎Programmers/Programmers.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,5 +522,8 @@
522522
<ClCompile Include="Lv2\Lv2_행렬테두리회전하기.cpp">
523523
<Filter>소스 파일</Filter>
524524
</ClCompile>
525+
<ClCompile Include="Lv2\Lv2_메뉴리뉴얼.cpp">
526+
<Filter>소스 파일</Filter>
527+
</ClCompile>
525528
</ItemGroup>
526529
</Project>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /