https://school.programmers.co.kr/learn/courses/30/lessons/12981
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
unorderedset 사용해 줬다. 나오지 않은 단어일 때, 끝말잇기 될 때 조건 처리 했다.
#include <string>
#include <vector>
#include <iostream>
#include <unordered_set>
using namespace std;
vector<int> solution(int n, vector<string> words) {
vector<int> answer;
char first_char = words[0][0];
unordered_set<string> s; // 여태 사용한 단어 담기
for (int i = 0; i < words.size(); i++)
{
if (s.find(words[i]) == s.end() && first_char == words[i][0]) // 여태 나오지 않은 단어면 , 끝말잇기 성립되면
{
s.insert(words[i]);
first_char = words[i][words[i].size() - 1];
}
else
{
answer.push_back(i % n + 1);
answer.push_back(i / n + 1);
return (answer);
}
}
answer.push_back(0);
answer.push_back(0);
return answer;
}
'<algorithm> > 프로그래머스' 카테고리의 다른 글
프로그래머스 예상 대진표 c++ (0) | 2023.05.28 |
---|---|
프로그래머스 구명보트 c++ (0) | 2023.05.28 |
프로그래머스 짝지어 제거하기 c++ (0) | 2023.05.26 |
프로그래머스 피보나치 수 c++ (0) | 2023.05.25 |
프로그래머스 다음 큰 숫자 c++ (0) | 2023.05.25 |