본문 바로가기

problem solving

[프로그래머스]모의고사

mod를 이용해 각 유저의 답을 순회할 수 있도록 했다.

답 확인이 끝난 후 정답의 횟수에 따라 조건문을 진행함으로써 answer을 구했다.

#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int user1[5= { 12345};
int user2[8= { 21232425 };
int user3[10= { 3311224455 };
vector<int> solution(vector<int> answers) {
    vector<int> answer;
    
    int count[3= { 0 };
    for(int i = 0; i < answers.size(); i++) {
        if(answers[i] == user1[i % 5]) {
            count[0]++;
        }
            
        if(answers[i] == user2[i % 8]) {
            count[1]++;
        }
        
        if(answers[i] == user3[i % 10]) {
            count[2]++;
        }     
    }
    
    answer.push_back(1);
    
    if(count[0< count[1]) {
        answer.clear();
        answer.push_back(2);
    }
    else if(count[0== count[1]) {
        answer.push_back(2);
    }
    
    if(count[answer[0- 1< count[2]) {
        answer.clear();
        answer.push_back(3);
    }
    else if(count[answer[0- 1== count[2]) {
        answer.push_back(3);
    }
    
    return answer;
}
cs