2022. 9. 30. 14:37 자기개발/코딩테스트
C++ (코딩테스트) - 모음사전(프로그래머스)
문제
https://school.programmers.co.kr/learn/courses/30/lessons/84512
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
char spell[5] = { 'A','E','I','O','U' };
char arr[5];
vector<string> dir;
void Permutation(int depth,int n, int r) {
if (depth == r) {
string s = "";
for (int j = 0; j < r; j++)
s.push_back(arr[j]);
dir.push_back(s);
return;
}
for (int i = 0; i < n; i++) {
arr[depth] = spell[i];
Permutation(depth + 1, n, r);
}
}
int solution(string word) {
for (int i = 0; i <= 5; i++)
Permutation(0, 5, i);
sort(dir.begin(), dir.end());
for (int j = 0; j < dir.size(); j++)
if (dir[j] == word) return j;
return -1;
}
'자기개발 > 코딩테스트' 카테고리의 다른 글
C++ (코딩테스트) - 튜플(프로그래머스) (1) | 2022.09.30 |
---|---|
C++ (코딩테스트) - [1차]캐시(프로그래머스) (1) | 2022.09.30 |
C++ (코딩테스트) - [1차] 뉴스 클러스터링(프로그래머스) (1) | 2022.09.30 |
C++ (코딩테스트) - 다음 큰 숫자(프로그래머스) (1) | 2022.09.30 |
C++ (코딩테스트) - 피보나치 수(프로그래머스) (0) | 2022.09.30 |