728x90
programmers.co.kr/learn/courses/30/lessons/72412
효율성 실패
#include <string>
#include <vector>
#include <iostream>
#include <unordered_map>
using namespace std;
vector<int> solution(vector<string> info, vector<string> query) {
vector<int> answer;
vector<string>qparse[100000];
unordered_map<int,int>scoremap;
string q;
for(int i=0; i<query.size(); i++){
q= query[i];
int j =0;
int t =0;
// cout<<i<<endl;
while(t<5){
string elem ="";
while(j<q.size() && q[j]!=' '){
elem+=q[j];
j++;
}
if(elem=="and"){j++;continue;}
if(elem=="-"){j++;t++;continue;}
qparse[i].push_back(elem);
t++;
j++;
// cout<<elem<<endl;
}
}
for(int i=0; i<query.size(); i++){
int count =0;
for(int p=0; p<info.size(); p++){
bool toggle = true;
for(int k=0; k<qparse[i].size(); k++){
string str = qparse[i][k];
// cout<<qparse[i].size()<<endl;
if(k==(qparse[i].size()-1)){
int l = info[p].size()-1;
string score;
int numscore;
if(scoremap.find(p)!=scoremap.end()){
numscore=scoremap[p];
}
else{
while(info[p][l]!=' '){
score=info[p][l]+score;
l--;
}
numscore = stoi(score);
scoremap[p]=numscore;
}
if(numscore<stoi(str)){
toggle = false;
break;
}
}
else{
if(info[p].find(str)==string::npos){
toggle =false;
break;
}
}
}
if(toggle == true){count++;}
}
answer.push_back(count);
}
return answer;
}
'프로그래머스 > KAKAO 2021 BLIND RECRUITMENT' 카테고리의 다른 글
광고삽입 (0) | 2021.02.21 |
---|---|
메뉴리뉴얼 (0) | 2021.02.08 |