[프로그래머스] Level.2 영어 끝말잇기
2021. 1. 18. 17:58ㆍAlgorithm/프로그래머스
코딩테스트 연습 - 영어 끝말잇기
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>
#include<unordered_map>
using namespace std;
vector<int> solution(int n, vector<string> words) {
int size, who, ord;
string first = "", last = "";
vector<int> answer;
unordered_map<string, int>cache;
for (string w : words) {
cache[w]++;
first = w[0];
if (cache.size() != 1) {
if (cache[w]>1 || last != first) {
size = (1 < cache[w]) ? cache.size() + 1 : cache.size();
who = (size % n == 0) ? n : size % n;
ord = (size%n == 0) ? size / n : size / n + 1;
answer.push_back(who);
answer.push_back(ord);
return answer;
}
}
last = w[w.size() - 1];
}
answer.push_back(0);
answer.push_back(0);
return answer;
}
'Algorithm > 프로그래머스' 카테고리의 다른 글
[프로그래머스] Level.2 완전탐색- 소수찾기 (0) | 2021.01.19 |
---|---|
[프로그래머스] Level.2 Dfs/Bfs -타겟넘버 (0) | 2021.01.19 |
[프로그래머스] Level.2 연습문제-큰 수 만들기 (0) | 2021.01.18 |
[프로그래머스]Level.2 연습문제 - 숫자의 표현 (0) | 2021.01.18 |
[프로그래머스]Level.2 연습문제- 올바른 괄호 (0) | 2021.01.17 |