짱아의 개발 기록장

2021 KAKAO BLIND RECRUITMENT : 순위 검색(c++) / String 본문

카테고리 없음

2021 KAKAO BLIND RECRUITMENT : 순위 검색(c++) / String

jungahshin 2021. 3. 9. 22:46
반응형

설명 추가 예정

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <algorithm>
 
using namespace std;
 
vector<int> db[4][3][3][3]; // 각 상태에 따른 점수를 저장
 
vector<int> solution(vector<string> info, vector<string> query) {
    vector<int> answer;
    
    for(int i=0; i<info.size(); i++){
        string word = "";
        int cnt = 0;
        int a, b, c, d, score = 0;
        for(istringstream is(info[i]); is >> word;)
        {
            if(cnt==0){
                if(word=="cpp"){
                    a = 0;
                }else if(word=="java"){
                    a = 1;
                }else{
                    a = 2;
                }
            }else if(cnt==1){
                if(word=="backend"){
                    b = 0;
                }else{
                    b = 1;
                }
            }else if(cnt==2){
                if(word=="junior"){
                    c = 0;
                }else{
                    c = 1;
                }
            }else if(cnt==3){
                if(word=="chicken"){
                    d = 0;
                }else{
                    d = 1;
                }
            }else{
                score = stoi(word);
            }
            cnt++;
        }
                
        db[a][b][c][d].push_back(score);
    }
    
    // db벡터들을 sorting해준다 -> 뒤에서 lower_bound를 해주기 위해서
    for(int i=0; i<=2; i++){
        for(int j=0; j<=1; j++){
            for(int k=0; k<=1; k++){
                for(int l=0; l<=1; l++){
                    sort(db[i][j][k][l].begin(), db[i][j][k][l].end()); 
                }
            }
        }
    }
    
    for(int i=0; i<query.size(); i++){
        string word = "";
        int cnt = 0;
        int a1, a2, b1, b2, c1, c2, d1, d2;
        int score = 0;
        for(istringstream is(query[i]); is >> word;)
        {
            if(word=="and"continue;
            if(cnt==0){
                if(word=="cpp"){
                    a1 = 0, a2 = 0;
                }else if(word=="java"){
                    a1 = 1, a2 = 1;
                }else if(word=="python"){
                    a1 = 2, a2 = 2;
                }else{
                    a1 = 0, a2 = 2;
                }
            }else if(cnt==1){
                if(word=="backend"){
                    b1 = 0, b2 = 0;
                }else if(word=="frontend"){
                    b1 = 1, b2 = 1;
                }else{
                    b1 = 0, b2 = 1;
                }
            }else if(cnt==2){
                if(word=="junior"){
                    c1 = 0, c2 = 0;
                }else if(word=="senior"){
                    c1 = 1, c2 = 1;
                }else{
                    c1 = 0, c2 = 1;
                }
            }else if(cnt==3){
                if(word=="chicken"){
                    d1 = 0, d2 = 0;
                }else if(word=="pizza"){
                    d1 = 1, d2 = 1;
                }else{
                    d1 = 0, d2 = 1;
                }
            }else{
                score = stoi(word);
            }
            cnt++;
        }
        
        int ans = 0;
        for(int i=a1; i<=a2; i++){
            for(int j=b1; j<=b2; j++){
                for(int k=c1; k<=c2; k++){
                    for(int l=d1; l<=d2; l++){
                        int n =  db[i][j][k][l].size();
                        int idx = lower_bound(db[i][j][k][l].begin(), db[i][j][k][l].end(), score) - db[i][j][k][l].begin();
                        ans += (n-idx);                         
                    }
                }
            }
        }
 
        answer.push_back(ans);
    }
    
    return answer;
}
cs
반응형
Comments