euisblue
42840. 모의고사

Level 1 모의고사

시간 복잡도: O(N)

1#include <bits/stdc++.h> 2 3using namespace std; 4 5vector<int> solution(vector<int> answers) { 6 vector<int> answer; 7 string a ="12345"; 8 string b = "21232425"; 9 string c = "3311224455"; 10 11 vector<int> cnt(3, 0); 12 13 for(int i=0; i<answers.size(); ++i) { 14 if(a[i%a.size()]-'0' == answers[i]) ++cnt[0]; 15 if(b[i%b.size()]-'0' == answers[i]) ++cnt[1]; 16 if(c[i%c.size()]-'0' == answers[i]) ++cnt[2]; 17 } 18 19 int max = *max_element(cnt.begin(), cnt.end()); 20 if(cnt[0] == max) answer.push_back(1); 21 if(cnt[1] == max) answer.push_back(2); 22 if(cnt[2] == max) answer.push_back(3); 23 return answer; 24}

수포자 삼인방의 찍는 패턴('12345', '21232425', '3311224455')을 문자열로 저장해두고, 이를 시험 총 문제 만큼 반복하면서 확인.

마지막으로 max_element를 사용해서 세 명중 누가 제일 잘 찍었는지 확인.