본문 바로가기
Coding Test/Programmers

[Programmers] Summer/Winter Coding(~2018) Lv 2. 영어 끝말잇기

by song.ift 2023. 5. 23.

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

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

vector<int> solution(int n, vector<string> words) {
    set<string> s;
    int cnt{ 0 };
    
    auto res = any_of(words.begin(), words.end(), [&](const auto& str)
    {
        const auto& lastWord = cnt ? words[cnt - 1].back() : words[0].front();
        if (s.find(str) != s.end() || lastWord != str.front())
            return true;
 
        s.insert(str), ++cnt;
        return false;
    });
    
    return res ? vector<int>{ cnt % n + 1, cnt / n + 1 } : vector<int>{ 0, 0 };
}

GitHub : https://github.com/developeSHG/Algorithm-Baekjoon_Programmers/blob/affb956311ebf88aee79d06b38e6f7dea3da5207/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/lv2/12981.%E2%80%85%EC%98%81%EC%96%B4%E2%80%85%EB%81%9D%EB%A7%90%EC%9E%87%EA%B8%B0/%EC%98%81%EC%96%B4%E2%80%85%EB%81%9D%EB%A7%90%EC%9E%87%EA%B8%B0.cpp

 

GitHub - developeSHG/Algorithm-Baekjoon_Programmers: 백준 and 프로그래머스 소스코드

백준 and 프로그래머스 소스코드. Contribute to developeSHG/Algorithm-Baekjoon_Programmers development by creating an account on GitHub.

github.com

 

댓글