◈ 문제 설명
◈ 문제 설명 링크
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
◈ 작성 코드
#include <string>
#include <vector>
using namespace std;
vector<int> solution(vector<int> answers)
{
vector<int> answer;
vector<int> one = {1,2,3,4,5}; // 5
vector<int> two = {2,1,2,3,2,4,2,5}; // 8
vector<int> three = {3,3,1,1,2,2,4,4,5,5}; // 10
vector<int> check = {0,0,0};
int t = 0;
int a = 0;
int b = 0;
int c = 0;
while(t < answers.size())
{
if(answers[t] == one[a])
{
check[0]++;
}
if(answers[t] == two[b])
{
check[1]++;
}
if(answers[t] == three[c])
{
check[2]++;
}
a++;
b++;
c++;
if(a > 4)
{
a = 0;
}
if(b > 7)
{
b = 0;
}
if(c > 9)
{
c = 0;
}
t++;
}
if(check[0] >= check[1] && check[0] >= check[2])
{
answer.push_back(1);
if(check[0] == check[1] && check[0] != check[2])
{
answer.push_back(2);
}
else if(check[0] != check[1] && check[0] == check[2])
{
answer.push_back(3);
}
else if(check[0] == check[1] && check[0] == check[2])
{
answer.push_back(2);
answer.push_back(3);
}
}
else if(check[1] >= check[0] && check[1] >= check[2])
{
answer.push_back(2);
if(check[1] != check[0] && check[1] == check[2])
{
answer.push_back(3);
}
}
else if(check[2] > check[0] && check[2] > check[1])
{
answer.push_back(3);
}
return answer;
}
'[프로그래머스 C++] > LEVEL 1' 카테고리의 다른 글
[프로그래머스 C++] 완주하지 못한 선수 (0) | 2025.03.31 |
---|---|
[프로그래머스 C++] K번째수 (0) | 2025.03.31 |
[프로그래머스 C++] 두 개 뽑아서 더하기 (0) | 2025.03.31 |
[프로그래머스 C++] 3진법 뒤집기 (0) | 2025.03.31 |
[프로그래머스 C++] 내적 (0) | 2024.04.24 |