순위 검색

eunheelog·2023년 6월 5일
0

programmers

목록 보기
5/15

프로그래머스 - 순위 검색

문제 요약


  • 지원서 작성 시 4가지 항목 필수 선택
    ① 개발언어 - cpp, java, python 中 1
    ② 지원 직군 - backend, frontend 中 1
    ③ 지원 경력구분 - junior, senior 中 1
    ④ 소울푸드 - chicken, pizza 中 1
  • 궁금해하는 내용
    → [조건]을 만족하는 사람 중 코딩테스트 점수를 X점 이상 받은 사람은 모두 몇 명인가?

제한 사항


  • info 배열은 "개발언어 직군 경력 소울푸드 점수" 형식
    → 각 단어는 공백으로 구분
  • query 배열은 "[조건] X" 형식
    → '-' 표시는 해당 조건을 고려하지 않겠다는 의미

SourceCode

#include <string>
#include <vector>
#include <sstream>
#include <iostream>

using namespace std;

vector<int> solution(vector<string> info, vector<string> query) {
    vector<int> answer;
    for(int i=0; i<query.size(); i++) {
        int idx = 0, cnt = 0;
        string str, input[5];
        stringstream ss(query[i]);
        while(ss >> str) {
            if(str != "and") {
                input[idx++] = str;
            }
        }
      
        for(int j=0; j<info.size(); j++) {
            int pass = 0, check = 0;
            idx = 0;
            while(idx < 4) {
                if(input[idx] == "-") {
                    pass++;
                }
                else if(info[j].find(input[idx]) != string::npos) {
                    pass++;
                }
                else {
                    check = 1;
                    break;
                }
                idx++;
            }
            if(check) continue;
            int score = stoi(info[j].substr(info[j].rfind(" ")));
            if(score >= stoi(input[4])) {
                pass++;
            }
            if(pass == 5) {
                cnt++;
            }
        }
        answer.push_back(cnt);
    }
   
    return answer;
}

→ 효율성 테스트에서 시간 초과,,

profile
⛧1일 1알고리즘⛧

0개의 댓글