-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathLv2_튜플.cpp
50 lines (45 loc) · 1.08 KB
/
Lv2_튜플.cpp
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
#include <string>
#include <vector>
#include <iostream>
#include <set>
#include <map>
using namespace std;
vector<int> solution(string s) {
vector<int> answer;
s = s.substr(1, s.length() - 2);
int idx = 0;
map<int, set<int>> m;
while (idx < s.length()) {
set<int> tuple;
int count = 0;
string temp = "";
while (idx++ < s.length()) {
if (isdigit(s[idx]))
temp += s[idx];
else if (temp != "") {
tuple.insert(stoi(temp));
++count;
temp = "";
if (s[idx] == '}') {
m.insert({ count, tuple });
break;
}
}
}
}
set<int> ans;
for (auto a : m) {
for (auto b : a.second) {
if (ans.count(b) == 0) {
answer.push_back(b);
ans.insert(b);
}
}
}
return answer;
}
int main() {
vector<int> ans = solution("{{2},{2,1},{2,1,3},{2,1,3,4}}");
for (auto a : ans)
cout << a << " ";
}