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 725a522

Browse files
committed
Lv2_튜플
1 parent 3fe9133 commit 725a522

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

‎Programmers/Lv2/Lv2_튜플.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <string>
2+
#include <vector>
3+
#include <iostream>
4+
#include <set>
5+
#include <map>
6+
using namespace std;
7+
8+
vector<int> solution(string s) {
9+
vector<int> answer;
10+
s = s.substr(1, s.length() - 2);
11+
12+
int idx = 0;
13+
map<int, set<int>> m;
14+
while (idx < s.length()) {
15+
set<int> tuple;
16+
int count = 0;
17+
string temp = "";
18+
while (idx++ < s.length()) {
19+
if (isdigit(s[idx]))
20+
temp += s[idx];
21+
else if (temp != "") {
22+
tuple.insert(stoi(temp));
23+
++count;
24+
temp = "";
25+
if (s[idx] == '}') {
26+
m.insert({ count, tuple });
27+
break;
28+
}
29+
}
30+
}
31+
}
32+
33+
set<int> ans;
34+
for (auto a : m) {
35+
for (auto b : a.second) {
36+
if (ans.count(b) == 0) {
37+
answer.push_back(b);
38+
ans.insert(b);
39+
}
40+
}
41+
}
42+
43+
return answer;
44+
}
45+
46+
int main() {
47+
vector<int> ans = solution("{{2},{2,1},{2,1,3},{2,1,3,4}}");
48+
for (auto a : ans)
49+
cout << a << " ";
50+
}

‎Programmers/Programmers.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@
295295
<ClCompile Include="Lv2\Lv2_탑.cpp">
296296
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
297297
</ClCompile>
298+
<ClCompile Include="Lv2\Lv2_튜플.cpp">
299+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
300+
</ClCompile>
298301
<ClCompile Include="Lv2\Lv2_폰켓몬.cpp">
299302
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
300303
</ClCompile>

‎Programmers/Programmers.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,5 +537,8 @@
537537
<ClCompile Include="Lv2\Lv2_수식최대화.cpp">
538538
<Filter>소스 파일</Filter>
539539
</ClCompile>
540+
<ClCompile Include="Lv2\Lv2_튜플.cpp">
541+
<Filter>소스 파일</Filter>
542+
</ClCompile>
540543
</ItemGroup>
541544
</Project>

0 commit comments

Comments
(0)

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