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;
}
 

+ Recent posts