Coding Test - cpp/String
[프로그래머스 lv 2 ] - 영어 끝말잇기
에드윈H
2021. 9. 25. 23:35
https://programmers.co.kr/learn/courses/30/lessons/12981
#include <string>
#include <vector>
#include <map>
using namespace std;
vector<int> solution(int n, vector<string> words) {
vector<int> answer;
map<string,int> m;
int size=words.size();
int i;
char lastWord;
bool find=false;
for(i=0;i<size;i++)
{
string curString=words[i];
m[curString]+=1;
if(m[curString]==2)
{
find=true;
break;
}else if( 0<i&&lastWord!=curString[0])
{
find=true;
break;
}
lastWord=curString[curString.size()-1];
}
if(find==false)
{
answer.push_back(0);
answer.push_back(0);
}else
{
answer.push_back(i%n+1);
answer.push_back(i/n+1);
}
return answer;
}