https://programmers.co.kr/learn/courses/30/lessons/12981
#include <string>
#include <vector>
#include <iostream>
#include <set>
using namespace std;
vector<int> solution(int n, vector<string> words) {
vector<int> answer;
answer.push_back(0);
answer.push_back(0);
set<string> wordSet;
wordSet.insert(words[0]);
char last = words[0][words[0].size()-1];
for(int i=1;i<words.size();i++){
if(words.size() == 1 || words[i][0] != last){
answer[0] = i%n +1;
answer[1] = i/n +1;
return answer;
}else{
last = words[i][words[i].size()-1];
if(wordSet.insert(words[i]).second == false){
answer[0] = i%n +1;
answer[1] = i/n +1;
return answer;
}
}
}
return answer;
}
#include <string>
#include <vector>
#include <iostream>
#include <map>
using namespace std;
vector<int> solution(int n, vector<string> words) {
int len=words.size();
map<string,int> h;
h[words[0]]=1;
for(int i=1;i<len;i++)
{
int len1=words[i-1].size();
if(h[words[i]] || (words[i-1][len1-1]!=words[i][0]))
return {i%n+1,i/n+1};
else
h[words[i]]=1;
}
return {0,0};
}