프로그래머스 모의고사
2019. 10. 4. 08:49ㆍ알고리즘/백준
답이 되는 배열을 저장해서 나머지 연산을 통해 실제 답과 비교해서 count를 한다
문제: https://programmers.co.kr/learn/courses/30/lessons/42840
깃허브주소: https://github.com/surinoel/boj/blob/master/Programmers_모의고사.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
#include <cstring> | |
using namespace std; | |
int a[5] = { 1, 2, 3, 4, 5 }; | |
int b[8] = { 2, 1, 2, 3, 2, 4, 2, 5 }; | |
int c[10] = { 3, 3, 1, 1, 2, 2, 4, 4, 5, 5 }; | |
vector<int> solution(vector<int> answers) { | |
vector<int> answer; | |
int score[3]; | |
memset(score, 0, sizeof(score)); | |
for (int i = 0; i < answers.size(); i++) { | |
if (answers[i] == a[i % 5]) { | |
score[0] += 1; | |
} | |
} | |
for (int i = 0; i < answers.size(); i++) { | |
if (answers[i] == b[i % 8]) { | |
score[1] += 1; | |
} | |
} | |
for (int i = 0; i < answers.size(); i++) { | |
if (answers[i] == c[i % 10]) { | |
score[2] += 1; | |
} | |
} | |
int maxv = -1; | |
for (int i = 0; i < 3; i++) { | |
if (maxv == -1 || score[i] > maxv) { | |
maxv = score[i]; | |
} | |
} | |
for (int i = 0; i < 3; i++) { | |
if (score[i] == maxv) { | |
answer.push_back(i + 1); | |
} | |
} | |
return answer; | |
} |
'알고리즘 > 백준' 카테고리의 다른 글
17472 다리 만들기 2 (0) | 2019.10.07 |
---|---|
2790 F7 (0) | 2019.10.06 |
10250 ACM 호텔 (0) | 2019.10.03 |
16935 배열 돌리기 3 (0) | 2019.10.02 |
16937 두 스티커 (0) | 2019.09.30 |