https://programmers.co.kr/learn/courses/30/lessons/12981
코딩테스트 연습 - 영어 끝말잇기
3 ["tank", "kick", "know", "wheel", "land", "dream", "mother", "robot", "tank"] [3,3] 5 ["hello", "observe", "effect", "take", "either", "recognize", "encourage", "ensure", "establish", "hang", "gather", "refer", "reference", "estimate", "executive"] [0,0]
programmers.co.kr
#include <string>
#include <vector>
#include <iostream>
using namespace std;
vector<int> solution(int n, vector<string> words) {
vector<int> answer;
vector<vector<string>> vec(10);
int a = 0;
int charSize = words[a].size();
char last_ch = words[a][charSize - 1];
int round = 1;
while (1) {
for (int i = 0; i < n; i++) {
if (a == 0) {
vec[i].push_back(words[a]);
a++;
continue;
}
//주어진 단어들로 탈락자가 생기지 않는다면, [0, 0]을 return 해주세요.
if (a == words.size()) {
answer.push_back(0);
answer.push_back(0);
return answer;
}
//이미 나왔던 단어면 탈락
for (int x = 0; x < a; x++) {
if (words[a] == words[x]) {
answer.push_back(i+1);
answer.push_back(round);
return answer;
}
}
if (last_ch == words[a][0]) {
vec[i].push_back(words[a]);
charSize = words[a].size();
last_ch = words[a][charSize - 1];
}
//끝말잇기 실패 탈락자 발생
else {
answer.push_back(i+1);
answer.push_back(round);
return answer;
}
a++;
}
round++;
}
}
'APS > 프로그래머스' 카테고리의 다른 글
[2020 KAKAO BLIND RECRUITMENT] 문자열 압축 C++ (0) | 2022.01.02 |
---|---|
[2017 카카오코드 본선] 단체사진 찍기 C++ (0) | 2021.12.31 |
[해시]위장 (0) | 2021.12.18 |
[Summer/Winter Coding(2019)] 멀쩡한 사각형 C++ (0) | 2021.12.18 |
[2018 KAKAO BLIND RECRUITMENT] [1차] 셔틀버스 C++ (0) | 2021.12.17 |