컴공 일기274
게시글 주소: https://orbi.kr/00071962271
https://school.programmers.co.kr/learn/courses/30/lessons/72411
카카오 코딩테스트 문제답습니다.
소위 코딩 근육을 묻는 문제같네요.
해시, 재귀, 조합, 문자열 파싱, 최대최소
각종 요소들이 복합적으로 어우러져 있습니다..
이런 문제는 구현하는데 시간 좀 잡아먹습니다.
많게는 2-3시간 걸릴 법한 문제죠.
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
unordered_map<string, int> course_map;
void generateCombinations(const string& str, string current, int index, int k)
{
if(current.size() == k)
{
course_map[current]++;
return;
}
if(index == str.size()) return;
//include
generateCombinations(str, current+str[index], index+1, k);
//not include
generateCombinations(str, current, index+1, k);
}
vector<string> solution(vector<string> orders, vector<int> course) {
vector<string> answer;
unordered_map<int, string> menu_map;
for(auto& order : orders)
{
sort(order.begin(), order.end());
}
//initialization of menu_map
for(int i=0; i<orders.size(); i++)
{
menu_map[i] = orders[i];
}
//initialization of course_map
for(const auto& course_length : course)
{
course_map.clear();
for(const auto& order : orders)
{
if(order.size() >= course_length)
{
generateCombinations(order, "", 0, course_length);
}
}
int max_count = 0;
for(const auto& [key, value] : course_map)
{
if(value > max_count)
{
max_count = value;
}
}
if(max_count >= 2)
{
for(const auto& [key, value] : course_map)
{
if(value == max_count)
{
answer.push_back(key);
}
}
}
}
sort(answer.begin(), answer.end());
return answer;
}
0 XDK (+0)
유익한 글을 읽었다면 작성자에게 XDK를 선물하세요.
-
속보) 라유 등장 7 2
두둥
-
시발2년연속으로이지랄나니까 1 0
사람정신이안무너지겠냐
-
2025 양정고 1학년 1학기 중간고사 1컷 70점이라네요~ 비쥬얼에 비하면 '아주...
-
1시간 자버렸어요 12 1
오늘도 늦게자기 각이네요..
-
걍 나란 사람이 문제인거같음 1 2
걍 누구든 오래 친분 유지하는경우가 잘 없는듯
-
삼수 3 0
현실적으로 삼수해도 괜찮나요? 삼수 서성한이면 나중에 취업할 때 지장 많을까요?...
-
늘 기대하는 시기가 있음 2 2
6모 당일 9모 당일 10평 즈음에 수능 전날 저녁(S급) 수능 다음날 낮 나는...
-
삼차방정식부터는 1 1
조립제법~~~
-
철수가 영희에게 똥침을 했다. 12 4
다음에 들어갈 문장으로 올바른 것은?
-
롤 아레나 할 사람~~ 19 0
선착순 한 명 히히
첫번째 댓글의 주인공이 되어보세요.