
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int answerCalculate(int _currentPerson, int _n)
{
_currentPerson++;
if (_currentPerson % _n == 0)
{
_currentPerson = _n;
}
else
{
_currentPerson = _currentPerson % _n;
}
return _currentPerson;
}
vector<int> solution(int n, vector<string> words) {
vector<int> answer;
vector<string> usedWords;
int currentTurn = 0;
int currentPerson = 0;
bool isOverlap = false;
for (int i = 0; i < words.size(); i++)
{
if (currentPerson % n == 0)
{
currentTurn++;
}
if (usedWords.empty() == false)
{
for (int j = 0; j < usedWords.size(); j++)
{
if (usedWords[j] == words[i])
{
cout << "중복" << endl;
answer.push_back(answerCalculate(currentPerson, n));
answer.push_back(currentTurn);
isOverlap = true;
break;
}
}
}
//중복되었으면 이후는 체크하지 않고 빠져나옴.
if (isOverlap)break;
if (i - 1 >= 0)
{
if (words[i][0] != words[i - 1][words[i - 1].length() - 1])
{
cout << "불일치" << endl;
answer.push_back(answerCalculate(currentPerson, n));
answer.push_back(currentTurn);
break;
}
}
//사용한 단어 벡터에 현재 단어를 넣는다.
usedWords.push_back(words[i]);
currentPerson++;
}
//마지막까지 탈락자가 나오지 않으면 0,0 추가
if (answer.empty())
{
answer.push_back(0);
answer.push_back(0);
}
return answer;
}
|
'프로그래머스 - 내 풀이 > 프로그래머스 Lv2' 카테고리의 다른 글
프로그래머스 / KAKAO BLIND RECRUITMENT / 오픈채팅방 (0) | 2022.02.11 |
---|---|
프로그래머스 / 월간 코드 챌린지 시즌1 / 삼각 달팽이도움말 (0) | 2021.04.07 |
프로그래머스 / Summer,Winter Coding(2019) / 멀쩡한 사각형 (0) | 2020.07.17 |
프로그래머스 / 스택,큐 / 주식 가격 (0) | 2020.07.17 |
프로그래머스 / 스택, 큐 / 프린터 (0) | 2020.06.18 |