#include <string>
#include <vector>
#include <iostream>
#include <map>
using namespace std;
 
vector<int> solution(int n, vector<string> words) 
{
    vector<int> answer;
    map<stringint> visited;
    int people = 0;
    int peopleTurn = 0;
    bool flag = false;
    
    for(int i = 0; i < words.size(); i++)
    {
        if(visited[words[i]] == 0)
        {   
            if(i == 0)
            {
                visited[words[i]] = 1;
                continue;
            }
            else
            {
                char last = words[i-1][words[i-1].size()-1];
                
                // 단어를 잘못 말한 경우
                if(last != words[i][0])
                {
                    if((i+1) % n == 0)
                    {
                        people = n;
                        peopleTurn = (i+1/ n;
                    }
                    else
                    {
                        people = (i+1) % n;
                        peopleTurn = (i+1/ n + 1;
                    }
                    
                    flag = true;
                    break;
                }
                else
                {
                    visited[words[i]] = 1;
                }
            }
        }
        // 나온 단어를 다시 말한 경우
        else
        {
            if((i+1) % n == 0)
            {
                people = n;
                peopleTurn = (i+1/ n;
            }
            else
            {
                people = (i+1) % n;
                peopleTurn = (i+1/ n + 1;
            }
            
            flag = true;
            break;
        }
    }
    
    if(flag)
    {
        answer.push_back(people);
        answer.push_back(peopleTurn);   
    }
    else
    {
        answer.push_back(0);
        answer.push_back(0);   
    }
 
    return answer;
}
cs

+ Recent posts