수포자는 수학을 포기한 사람의 준말입니다. 수포자 삼인방은 모의고사에 수학 문제를 전부 찍으려 합니다. 수포자는 1번 문제부터 마지막 문제까지 다음과 같이 찍습니다.
1번 수포자가 찍는 방식: 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, ...
2번 수포자가 찍는 방식: 2, 1, 2, 3, 2, 4, 2, 5, 2, 1, 2, 3, 2, 4, 2, 5, ...
3번 수포자가 찍는 방식: 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, 3, 3, 1, 1, 2, 2, 4, 4, 5, 5, ...
1번 문제부터 마지막 문제까지의 정답이 순서대로 들은 배열 answers가 주어졌을 때, 가장 많은 문제를 맞힌 사람이 누구인지 배열에 담아 return 하도록 solution 함수를 작성해주세요.
나머지를 인덱스로
사용하자 !!!SourceCode
#include <string> #include <vector> using namespace std; vector<int> solution(vector<int> answers) { vector<int> answer; int student1[5] = {1, 2, 3, 4, 5}; // 1번 수포자 int student2[8] = {2, 1, 2, 3, 2, 4, 2, 5}; // 2번 수포자 int student3[10] = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; // 3번 수포자 int score[3] = {0}, cutline = 0; // 학생별 점수 for(int i=0; i<answers.size(); i++) { if(answers[i] == student1[i % 5]) { score[0]++; cutline = max(score[0], cutline); } if(answers[i] == student2[i % 8]) { score[1]++; cutline = max(score[1], cutline); } if(answers[i] == student3[i % 10]) { score[2]++; cutline = max(score[2], cutline); } } for(int i=0; i<3; i++) { if(cutline == score[i]) { answer.push_back(i+1); } } return answer; }
*
연산자를 붙여서 *max_element(arr, arr+size)
이런식으로 써야한다 !