코드
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#define S second
#define F first
using namespace std;
char text[3] = { '}','{',',' };
vector<int> solution(string s) {
vector<int> answer;
// pq<tuple.size , tuple, order by asc>
priority_queue <pair<int, vector<int>>, vector<pair<int, vector<int>>>, greater<pair<int, vector<int>>>> pq;
pair<int, vector<int>> temp;
string num;
for (int i = 0; i < s.size() - 1; i++) {
if (s[i] != ',' && s[i] != '{' && s[i] != '}') num += s[i];
if (!num.empty() && (s[i] == ',' || s[i] == '}')) {
temp.S.push_back(stoi(num));
num.clear();
}
if (s[i] == '}') {
temp.F = temp.S.size();
pq.push(temp);
temp.S.clear();
}
}
map<int, bool> m;
while (!pq.empty()) {
temp = pq.top();
pq.pop();
for (int i = 0; i < temp.F; i++) {
if (m.find(temp.S[i]) == m.end()) {
m[temp.S[i]] = true;
answer.push_back(temp.S[i]);
break;
}
}
}
return answer;
}
int main() {
string s = "{{2},{2,1},{2,1,3},{2,1,3,4}}";
vector<int> ret = solution(s);
cout << ret.size();
return 0;
}