알고리즘/프로그래머스
프로그래머스 - 모의고사 c++
안알랴줌.
2019. 9. 6. 00:10
문제의 주요포인트는 아래와 같다.
1. 학생 1,2,3 의 찍기 패턴을 설정하는것
2. 문제의수가 찍기 패턴보다 많을시 어떻게 할것인지
#include <string>
#include <vector>
#include <math.h>
using namespace std;
vector<int> first = {1,2,3,4,5}; //5
vector<int> second = {2, 1, 2, 3, 2, 4, 2, 5}; //8
vector<int> third = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; //10
int cnt1;
int cnt2;
int cnt3;
vector<int> solution(vector<int> answers) {
vector<int> answer;
int cnt =0;
for(int i=0; i< answers.size(); ++i){
int i1 = i%5;
int i2 = i%8;
int i3 = i%10;
if( answers[i] == first[i1]) cnt1++;
if( answers[i] == second[i2]) cnt2++;
if( answers[i] == third[i3]) cnt3++;
}
int maxscore = max(cnt1, max(cnt2, cnt3));
if(maxscore == cnt1) answer.push_back(1);
if(maxscore == cnt2) answer.push_back(2);
if(maxscore == cnt3) answer.push_back(3);
return answer;
}