백준
백준 소스코드 [C++] 1759 암호 만들기
Hani_Levenshtein
2021. 6. 11. 23:36
https://www.acmicpc.net/problem/1759
1759번: 암호 만들기
첫째 줄에 두 정수 L, C가 주어진다. (3 ≤ L ≤ C ≤ 15) 다음 줄에는 C개의 문자들이 공백으로 구분되어 주어진다. 주어지는 문자들은 알파벳 소문자이며, 중복되는 것은 없다.
www.acmicpc.net
백준 소스코드 [C++] 1759 암호 만들기
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <sstream>
#include <cstdlib>
#include <cassert>
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define pli pair<ll, int>
#define make_unique(v) sort(all(v)), v.erase(unique(all(v)), v.end())
typedef long long ll;
using namespace std;
int n, m;
vector<char> substring;
void getPassword(int subPassword, string password, int con, int vow)
{
if (password.size() == n){
if (con < 2 || vow < 1) return;
cout << password << '\n';
}
for (int ith = subPassword; ith < m; ith++){
if (substring[ith] == 'a' || substring[ith] == 'e' || substring[ith] == 'i' || substring[ith] == 'o' || substring[ith] == 'u')
getPassword(ith + 1, password + substring[ith], con, vow + 1);
else
getPassword(ith + 1, password + substring[ith], con + 1, vow);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
substring.resize(m);
for (int i = 0; i < m; i++) cin >> substring[i];
sort(all(substring));
getPassword(0, "", 0, 0);
return 0;
}