https://school.programmers.co.kr/learn/courses/30/lessons/12981

#include <string>
#include <vector>
#include <iostream>
#include<unordered_map>
using namespace std;

vector<int> solution(int n, vector<string> words) {
    vector<int> answer{0, 0};
    unordered_map<string, string>um;
    // [실행] 버튼을 누르면 출력 값을 볼 수 있습니다. 

    for(int idx = 0; idx < words.size(); ++idx){
        if(um.empty() == false &&
           ((um.find(words[idx]) != um.end()) ||
            words[idx-1][words[idx-1].size()-1] != words[idx][0]
          )){
            int tmp = (idx + 1 ) %n;
            if(tmp ==0) tmp = n;
            answer[0] = tmp;
            answer[1] = (idx / n) +1 ;
            return answer;
        }
        else{
            um[words[idx]] = words[idx];
        }
    }

    return answer;
}

+ Recent posts