코테는 역시 풀어본문제만큼 아는것 같음
https://programmers.co.kr/learn/courses/30/lessons/64065
#include <string>
#include <vector>
#include <set>
#include <iostream>
#include <algorithm>
using namespace std;
vector<string> strtok(string str, char delim = ' '){ // strtok
vector<string> ret;
int prev=0;
for(int i=0;i<str.size();i++){
if(str[i]==delim){
ret.push_back(str.substr(prev,i-prev));
prev=i+1;
}
}
if(str.size()!=prev)
ret.push_back(str.substr(prev,str.size()-prev));
return ret;
}
bool cmp(const string &a, const string &b) {
return a.size() < b.size() ? true : false;
}
vector<int> solution(string s) {
vector<int> answer;
set<string> numSet;
string str = s.substr(0, s.size()-2);
vector<string> tup = strtok(str, '}');
sort(tup.begin(), tup.end(), cmp);
for(string t: tup){
string numS = t.substr(2, t.size()-1);
vector<string> num = strtok(numS, ',');
for(string n :num){
if(numSet.insert(n).second != false)
answer.push_back(stoi(n));
}
}
return answer;
}
#include <bits/stdc++.h>
using namespace std;
vector<int> solution(string s) {
int st[101010]={};
vector<int> answer;
string tmp;
for(char i: s){
if(i-'0' >=0 && i-'0' <=9){
tmp += i;
}
else{
if(tmp.length())
st[stoi(tmp)]++, tmp.clear();
}
}
vector<pair<int, int>> v;
for(int i =0; i <101010; i++)
if(st[i])
v.push_back({st[i], i});
sort(v.begin(), v.end());
reverse(v.begin(),v.end());
for(auto it: v) answer.push_back(it.second);
return answer;
}