강의로 돌아가기
Petrus Kim

VB / Option Base 1 개념이 필요하겠네요.

vector solution(vector answers)
{
vector> students({ vector({ 1, 2, 3, 4, 5 }), vector({ 2, 1, 2, 3, 2, 4, 2, 5 }), vector({ 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 }) });
vector score(students.size());
vector answer(1);

for (int j = 0; j < students.size(); ++j)
{
    for (int i = 0; i < answers.size(); ++i)
    {
        if (answers.at(i) == (students.at(j)).at(i % ((students.at(j)).size()))) // correct!
        {
            score.at(j) += 1;
        }
    }

    if (score.at(answer.at(0)) < score.at(j))
        answer.at(0) = j;
    else if (score.at(answer.at(0)) == score.at(j) && j > 0)
        answer.push_back(j);
}

for (int i = 0; i < answer.size(); ++i)
    ++answer.at(i);
return answer;

}

작성중인 코드―solution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <string>
#include <vector>

using namespace std;


vector<int> solution(vector<int> answers)
{
    vector<vector<int>> students({ vector<int>({ 1, 2, 3, 4, 5 }), vector<int>({ 2, 1, 2, 3, 2, 4, 2, 5 }), vector<int>({ 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 }) });
    vector<int> score(students.size());
    vector<int> answer(1);

    for (int j = 0; j < students.size(); ++j)
    {
        for (int i = 0; i < answers.size(); ++i)
        {
            if (answers.at(i) == (students.at(j)).at(i % ((students.at(j)).size()))) // correct!
            {
                score.at(j) += 1;
            }
        }

        if (score.at(answer.at(0)) < score.at(j))
            answer.at(0) = j;
        else if (score.at(answer.at(0)) == score.at(j) && j > 0)
            answer.push_back(j);
    }

    for (int i = 0; i < answer.size(); ++i)
        ++answer.at(i);
    return answer;
}
0 개의 답변
답변 쓰기
이 입력폼은 마크다운 문법을 지원합니다. 마크다운 가이드 를 참고하세요.