-
[Programmers] 모의고사STUDYING/Algorithm 2021. 9. 27. 00:35728x90
https://programmers.co.kr/learn/courses/30/lessons/42840
C++
#include <string> #include <vector> using namespace std; vector<int> solution(vector<int> answers) { vector<int> a = { 1, 2, 3, 4, 5 }; vector<int> b = { 2, 1, 2, 3, 2, 4, 2, 5 }; vector<int> c = { 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 }; int cntA = 0, cntB = 0, cntC = 0; vector<int> result; int len = answers.size(); for (int i = 0; i < len; ++i) { int tempA = a[i%5]; int tempB = b[i%8]; int tempC = c[i%10]; if (tempA == answers[i]) cntA++; if (tempB == answers[i]) cntB++; if (tempC == answers[i]) cntC++; } int maxCount = max(cntA, max(cntB, cntC)); if(maxCount == cntA) result.push_back(1); if(maxCount == cntB) result.push_back(2); if(maxCount == cntC) result.push_back(3); return result; }
'STUDYING > Algorithm' 카테고리의 다른 글
[Programmers] 타겟 넘버 (0) 2021.09.27 [Programmers] 체육복 (0) 2021.09.27 [Programmers] K번째 수 (0) 2021.09.27 [Programmers] 완주하지 못한 선수 (0) 2021.09.27 [Programmers] 멀쩡한 사각형 (0) 2021.09.27