https://programmers.co.kr/learn/courses/30/lessons/72412
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v[3][2][2][2];
vector<int> solution(vector<string> info, vector<string> query) {
vector<int> answer;
for (int i = 0; i<info.size(); i++) {
string tmp;
int lang, job, exp, food;
int index = 0;
int start = 0;
while (info[i][index] != ' ' && index <info[i].size()) {
index += 1;
}
tmp = info[i].substr(start, index - start);
if (tmp == "cpp") lang = 0;
else if (tmp == "java") lang = 1;
else if (tmp == "python") lang = 2;
start = index+1;
index += 1;
while (info[i][index] != ' ' && index <info[i].size()) {
index += 1;
}
tmp = info[i].substr(start, index - start);
if (tmp == "backend") job = 0;
else if (tmp == "frontend") job = 1;
start = index + 1;
index += 1;
while (info[i][index] != ' ' && index <info[i].size()) {
index += 1;
}
tmp = info[i].substr(start, index - start);
if (tmp == "junior") exp = 0;
else if (tmp == "senior") exp = 1;
start = index + 1;
index += 1;
while (info[i][index] != ' ' && index <info[i].size()) {
index += 1;
}
tmp = info[i].substr(start, index - start);
if (tmp == "chicken") food = 0;
else if (tmp == "pizza") food = 1;
tmp = info[i].substr(index+1);
v[lang][job][exp][food].push_back(stoi(tmp));
}
for (int i = 0; i<3; i++) {
for (int j = 0; j<2; j++) {
for (int k = 0; k<2; k++) {
for (int l = 0; l<2; l++) {
sort(v[i][j][k][l].begin(), v[i][j][k][l].end());
}
}
}
}
for (int i = 0; i<query.size(); i++) {
int lang, job, exp, food, score, ans = 0;
string tmp;
int index = 0;
int start = 0;
while (query[i][index] != ' ' && index <query[i].size()) {
index += 1;
}
tmp = query[i].substr(start, index - start);
if (tmp == "cpp") lang = 0;
else if (tmp == "java") lang = 1;
else if (tmp == "python") lang = 2;
else if (tmp == "-") lang = -1;
index += 5;
start = index;
while (query[i][index] != ' ' && index <query[i].size()) {
index += 1;
}
tmp = query[i].substr(start, index - start);
if (tmp == "backend") job = 0;
else if (tmp == "frontend") job = 1;
else if (tmp == "-") job = -1;
index += 5;
start = index;
while (query[i][index] != ' ' && index <query[i].size()) {
index += 1;
}
tmp = query[i].substr(start, index - start);
if (tmp == "junior") exp = 0;
else if (tmp == "senior") exp = 1;
else if (tmp == "-") exp = -1;
index += 5;
start = index;
while (query[i][index] != ' ' && index <query[i].size()) {
index += 1;
}
tmp = query[i].substr(start, index - start);
if (tmp == "chicken") food = 0;
else if (tmp == "pizza") food = 1;
else if (tmp == "-") food = -1;
index += 1;
tmp = query[i].substr(index);
for (int i = 0; i<3; i++) {
if (lang != -1 && lang != i) continue;
for (int j = 0; j<2; j++) {
if (job != -1 && job != j) continue;
for (int k = 0; k<2; k++) {
if (exp != -1 && exp != k) continue;
for (int l = 0; l<2; l++) {
if (food != -1 && food != l) continue;
int location = lower_bound(v[i][j][k][l].begin(), v[i][j][k][l].end(), stoi(tmp)) - v[i][j][k][l].begin();
ans += v[i][j][k][l].size() - location;
}
}
}
}
answer.push_back(ans);
ans = 0;
}
return answer;
}
'프로그래머스' 카테고리의 다른 글
카드 짝 맞추기 C++ (0) | 2021.08.01 |
---|---|
광고 삽입 C++ (0) | 2021.07.07 |
메뉴 리뉴얼 C++ (0) | 2021.06.30 |
신규 아이디 C++ (0) | 2021.06.28 |
가장 먼 노드 C++ (0) | 2021.04.22 |