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 d774884

Browse files
committed
Lv2_모음사전
1 parent 25c3bee commit d774884

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

‎Programmers/Lv2/Lv2_모음사전.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include <string>
2+
#include <vector>
3+
#include <iostream>
4+
#include <algorithm>
5+
using namespace std;
6+
7+
vector<string> words;
8+
const string w[] = {"A","E","I","O","U"};
9+
10+
bool cmp(string s1, string s2) {
11+
int len1 = s1.length();
12+
int len2 = s2.length();
13+
14+
if (len1 < len2) {
15+
for (int i = 0; i < len1; ++i) {
16+
if (s1[i] < s2[i])
17+
return true;
18+
else if (s1[i] == s2[i])
19+
continue;
20+
else
21+
return false;
22+
}
23+
return true;
24+
}
25+
else if (len1 == len2) {
26+
for (int i = 0; i < len1; ++i) {
27+
if (s1[i] < s2[i])
28+
return true;
29+
else if (s1[i] == s2[i])
30+
continue;
31+
else
32+
return false;
33+
}
34+
}
35+
else {
36+
for (int i = 0; i < len2; ++i) {
37+
if (s1[i] < s2[i])
38+
return true;
39+
else if (s1[i] == s2[i])
40+
continue;
41+
else
42+
return false;
43+
}
44+
return false;
45+
}
46+
47+
return true;
48+
}
49+
50+
void insertString(string s, int cnt, int goal) {
51+
if (cnt == goal) {
52+
words.push_back(s);
53+
return;
54+
}
55+
56+
for (int i = 0; i < 5; ++i) {
57+
insertString(s+w[i], cnt + 1, goal);
58+
}
59+
}
60+
61+
int solution(string word) {
62+
int answer = 0;
63+
64+
for (int i = 1; i <= 5; ++i)
65+
insertString("", 0, i);
66+
67+
sort(words.begin(), words.end(), cmp);
68+
69+
for (int i = 0; i < words.size(); ++i) {
70+
if (words[i] == word) {
71+
answer = i + 1;
72+
break;
73+
}
74+
}
75+
76+
return answer;
77+
}
78+
79+
int main() {
80+
cout << solution("AAAAE");
81+
return 0;
82+
}

‎Programmers/Programmers.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@
242242
<ClCompile Include="Lv2\Lv2_메뉴리뉴얼.cpp">
243243
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
244244
</ClCompile>
245+
<ClCompile Include="Lv2\Lv2_모음사전.cpp">
246+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
247+
</ClCompile>
245248
<ClCompile Include="Lv2\Lv2_빛의경로사이클.cpp">
246249
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
247250
</ClCompile>

‎Programmers/Programmers.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@
585585
<ClCompile Include="Lv2\Lv2_전력망을둘로나누기.cpp">
586586
<Filter>소스 파일\Lv2</Filter>
587587
</ClCompile>
588+
<ClCompile Include="Lv2\Lv2_모음사전.cpp">
589+
<Filter>소스 파일\Lv2</Filter>
590+
</ClCompile>
588591
</ItemGroup>
589592
<ItemGroup>
590593
<None Include="packages.config" />

0 commit comments

Comments
(0)

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