Skip to content

Commit be97402

Browse files
committed
Programmers: 프로그래머스 고득점 kit 전수 검사 모의고사 문제 추가 및 리드미 추가.
1 parent 8da472a commit be97402

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@
5959
- [해시 더 맵게](https://github.com/Crazy0416/algorithm/tree/master/programmers/hash/MoreHot)
6060
- [정렬 k번째수](https://github.com/Crazy0416/algorithm/tree/master/programmers/sort/KNumber)
6161
- [정렬 가장 큰 수](https://github.com/Crazy0416/algorithm/tree/master/programmers/sort/BiggistNumber)
62+
- [전수 검사 모의고사](https://github.com/Crazy0416/algorithm/tree/master/programmers/full_search/MockExam)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
project(MockExam)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(MockExam main.cpp)
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 프로그래머스 고득점 kit 전수 검사 모의 고사
2+
3+
## 해결 아이디어
4+
5+
- 그냥 전수 검사
6+
- 하지만 코드의 반복은 싫어하기 때문에 반복 패턴을 이차원 벡터에 저장.
7+
- 수포자의 정답 찍기 패턴이 반복되기 때문에 문제와 비교하기 위해서 modular 연산이 필요
8+
- ```supojas[supoIdx][i % supojas[supoIdx].size()] == answers[i]```
9+
- 핵심 알고리즘
10+
```
11+
for(int i = 0; i < answers.size(); i++) {
12+
for(int supoIdx = 0; supoIdx < 3; supoIdx++ ){
13+
if(supojas[supoIdx][i % supojas[supoIdx].size()] == answers[i]) {
14+
scores[supoIdx]++;
15+
}
16+
}
17+
}
18+
19+
int max_score = *max_element(scores.begin(), scores.end());
20+
21+
for(int supoIdx = 0; supoIdx < 3; supoIdx++ ){
22+
if(max_score == scores[supoIdx]) {
23+
answer.push_back(supoIdx + 1);
24+
}
25+
}
26+
27+
sort(answer.begin(), answer.end());
28+
return answer;
29+
```
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <vector>
4+
#include <algorithm>
5+
6+
using namespace std;
7+
8+
void showData(vector<int> data) {
9+
for(auto iter = data.begin(); iter != data.end(); iter++)
10+
cout << *iter << " ";
11+
cout << endl;
12+
}
13+
14+
vector<int> solution(vector<int> answers) {
15+
vector<int> answer;
16+
vector<int> scores = {0, 0, 0};
17+
vector<vector<int>> supojas = {{1, 2, 3, 4, 5},
18+
{2, 1, 2, 3, 2, 4, 2, 5},
19+
{3, 3, 1, 1, 2, 2, 4, 4, 5, 5}};
20+
21+
for(int i = 0; i < answers.size(); i++) {
22+
for(int supoIdx = 0; supoIdx < 3; supoIdx++ ){
23+
if(supojas[supoIdx][i % supojas[supoIdx].size()] == answers[i]) {
24+
scores[supoIdx]++;
25+
}
26+
}
27+
}
28+
29+
int max_score = *max_element(scores.begin(), scores.end());
30+
31+
for(int supoIdx = 0; supoIdx < 3; supoIdx++ ){
32+
if(max_score == scores[supoIdx]) {
33+
answer.push_back(supoIdx + 1);
34+
}
35+
}
36+
37+
sort(answer.begin(), answer.end());
38+
return answer;
39+
}
40+
41+
int main() {
42+
vector<int> answers = {1, 2, 3, 4, 5};
43+
showData(solution(answers));
44+
return 0;
45+
}

0 commit comments

Comments
 (0)