문제 링크

 

 

내 풀이 

#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int su1 [5]  = {1, 2, 3, 4, 5}; 
int su2 [8] = {2, 1, 2, 3, 2, 4, 2, 5};
int su3 [10] = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};


vector<int> solution(vector<int> answers) {
    vector<int> answer;
    vector<int> corr(0);
    int po1, po2, po3, a, b, c = 0;
    
    for(int i=0; i < 5; i++){
        if(answers[i] == su1[po1]) a++; 
        if(answers[i] == su2[po2]) b++;
        if(answers[i] == su3[po3]) c++;
        po1++;
        po2++;
        po3++;
        if(po1 > 4) po1=0;
        if(po2 > 7) po2=0;
        if(po3 > 9) po3=0;
    } 
    corr.push_back(a);
    corr.push_back(b);
    corr.push_back(c);
    
    auto valmax = *max_element(corr.begin(), corr.end());
    if(valmax==corr.at(0)) answer.push_back(1);
    if(valmax==corr.at(1)) answer.push_back(2);
    if(valmax==corr.at(2)) answer.push_back(3);

    
    sort(answer.begin(), answer.end());  
    return answer;
}

'CPP 문제풀이 > 프로그래머스' 카테고리의 다른 글

위장 (해시)  (0) 2020.09.26
전화번호 목록 (해시)  (0) 2020.09.26
기능개발  (0) 2020.08.02
  (0) 2020.08.02
프린터  (0) 2020.08.02
블로그 이미지

hjc_

୧( “̮ )୨

,