- answers : 1번 문제부터 마지막 문제까지의 정답이 순서대로 들은 배열
_ 시험 : 최대 10,000 문제
_ 문제의 정답 : 1, 2, 3, 4, 5중 하나
_ 가장 높은 점수를 받은 사람이 여럿일 경우, return하는 값을 오름차순 정렬
- 1번 방식 : {1, 2, 3, 4, 5}, 5개
- 2번 방식 : {2, 1, 2, 3, 2, 4, 2, 5}, 8개
- 3번 방식 : {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}, 10개
- int cnt[3] : 수포자들의 정답수
- for문(i) : 0 ~ answers.size()
- if (answer[i] == 수포자들) cnt[수포자들]++
- max 구하기
- for문(i) : 0 ~ 3
if (cnt == max) answer.push_back(i+1)
[2020.08.09] 성공
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> answers) {
vector<int> answer;
int cnt[3] = {0}, max = 0;
int one[5] = {1, 2, 3, 4, 5};
int two[8] = {2, 1, 2, 3, 2, 4, 2, 5};
int three[10] = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};
for(int i=0; i<answers.size(); i++) {
if(answers[i] == one[i%5]) cnt[0]++;
if(answers[i] == two[i%8]) cnt[1]++;
if(answers[i] == three[i%10]) cnt[2]++;
}
for(int i=0; i<3; i++) {
if(max < cnt[i]) max = cnt[i];
}
for(int i=0; i<3; i++) {
if(cnt[i] == max) answer.push_back(i+1);
}
return answer;
}
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> answers) {
vector<int> answer;
int cnt[3] = {0}, max = 0,
one[5] = {1, 2, 3, 4, 5},
two[8] = {2, 1, 2, 3, 2, 4, 2, 5},
three[10] = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5};
for(int i = 0; i < answers.size(); i++) {
if(answers[i] == one[i % 5]) cnt[0]++;
if(answers[i] == two[i % 8]) cnt[1]++;
if(answers[i] == three[i % 10]) cnt[2]++;
}
for(int i = 0; i < 3; i++)
if(max < cnt[i]) max = cnt[i];
if(cnt[0] == max) answer.push_back(1);
if(cnt[1] == max) answer.push_back(2);
if(cnt[2] == max) answer.push_back(3);
return answer;
}