-
Notifications
You must be signed in to change notification settings - Fork 1
20-froglike6 #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
20-froglike6 #77
Conversation
|
์ด..์ฌ์ด ๊ฑฐ ๋ง๋์ ์ ์กฐ๊ฑด์ ์๋ชป ์ฝ์ด์(๊ทธ๋ฅ ์กฐํฉ์ ๋ชจ์ ์ต์ ํ๋๋ง ์์ผ๋ฉด ๋๋ ์ค ์์์ต๋๋ค.) ๋ํ๋์ ์๋์ฝ๋๋ฅผ ์ฐธ๊ณ ํด์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค ๐ซ ์ ๋ ๋ฐฑํธ๋ํน์ผ๋ก ๋ฌธ์์ด ์กฐํฉ์ ์ฐพ์๊ฐ๋ฉด์, ๊ธธ์ด๊ฐ 4๋ฅผ ๋ง์กฑํ๋ฉด์, a, e, i, o, u๊ฐ ๋ค์ด ์๋ ๋ฌธ์์ด๋ค์ ์ถ๋ ฅํ๋๋ก ํ์์ต๋๋ค. #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
// a c i s t w
int l,c;
char vowels[5] = {'a', 'e', 'i', 'o','u'};
void comb(string& s, string out, int idx, int len)
{
char v_cnt =0;
if (len == l)
{
for (char vowel : vowels)
{
if (out.find(vowel) != string::npos) v_cnt++;
}
if (l - v_cnt >= 2 && v_cnt >= 1)
cout << out << '\n';
return;
}
for (int i=idx;i<c;i++){
comb(s, out +s[i], i+1, len+1);
}
}
int main()
{
cin >> l >> c;
string s; char s_t;
for (int i=0;i<c;i++)
{
cin >> s_t;
s += s_t;
}
sort(s.begin(), s.end());
comb(s, "", 0, 0);
}
|
|
์ ๋ ์ ํ๋์ฒ๋ผ ๋ฐฑํธ๋ํน์ ์ฌ์ฉํ์ฌ ํ์์ต๋๋ค. ์ฝ๋๋ ์ด์ง ๋ค๋ฅด๋ค์. #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int L, C;
vector<char> chars;
vector<char> password;
void dfs(int start, int depth) {
if(depth == L) {
int vowel = 0, consonant = 0;
for(char c : password) {
if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') vowel++;
else consonant++;
}
if(vowel >= 1 && consonant >= 2) {
for(char c : password)
cout << c;
cout << '\n';
}
return;
}
for(int i = start; i < C; ++i) {
password.push_back(chars[i]);
dfs(i+1, depth+1);
password.pop_back();
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin >> L >> C;
chars.resize(C);
for(int i = 0; i < C; ++i)
cin >> chars[i];
sort(chars.begin(), chars.end());
dfs(0, 0);
return 0;
} |
hadongun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combinations !!!
vowel_count = sum(1 for ch in comb if ch in vowels)
์ด๋ฐ ์์ผ๋ก ์ฝ๋๋ฅผ ์๋นํ ๊ฐ๊ฒฐํ๊ฒ ์งค ์ ์๋ค๋๊ฒ ํ์ด์ฌ์ ์ฅ์ ์ธ ๊ฒ ๊ฐ์ต๋๋ค
๋ชจ์์ ํ๋ํ๋ ๋ณด๋ฉด์ comb์ ์๋ค๋ฉด 1์ ๋ํ๋ ์์ผ๋ก ํ๋ ๋งค์ฐ ์ฝ๋๊ฐ ๊ฐ๊ฒฐํด์ง๋๊ตฐ์ฉ
์ด์ ์ฑ๊ธฐ๊ธฐ
import sys
from itertools import combinations
input = sys.stdin.readline
L, C = map(int, input().split())
code = input().split()
code.sort()
vowels = {'a', 'e', 'i', 'o', 'u'}
for comb in combinations(code, L):
vowel_count = sum(1 for ch in comb if ch in vowels)
not_vowel_count = L - vowel_count
if vowel_count >= 1 and not_vowel_count >= 2:
print(''.join(comb))
๐ ๋ฌธ์ ๋งํฌ
์ํธ ๋ง๋ค๊ธฐ
โ๏ธ ์์๋ ์๊ฐ
20๋ถ
โจ ์๋ ์ฝ๋
์๋ ์ฝ๋
๋ฒ์จ 20๋ฒ์งธ pr์ด๋ค์...๐ฅน๐ฅน ์ต๊ทผ ๋ฌธ์ ๋ค์ ๋ณด๋ค ๋ณด๋, ๋๋ฌด ์ด๋ ค์ด ๊ฒ๋ค์ด ๋ง์ ์ฌ์ด ๋ฌธ์ ๋ฅผ ๋ค๊ณ ์์ต๋๋ค.
์ด ๋ฌธ์ ๋ ๊ฐ๋ฅํ ์กฐ๊ฑด์ ๋ฌธ์์ด์ ๋ชจ๋ ์ถ๋ ฅํ๋ ๋ฌธ์ ์ ๋๋ค. ๊ฐ๋ฅํ ์กฐ๊ฑด์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
์์ 3๊ฐ์ง๋ฅผ ๋ชจ๋ ๋ง์กฑํ๋ ๋ฌธ์์ด์ ์ฌ์ ์์ผ๋ก ์ถ๋ ฅํ๋ฉด ๋๋ ๋ฌธ์ ์ ๋๋ค.
์ ๋ ํ์ด์ฌ์
combinations์ ์ฌ์ฉํด์ ๋ค๋ฅธ ์ธ์ด๋ณด๋ค ๋น๊ต์ ์ฝ๊ฒ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค.for์์ ๊ฐ๋ฅํ ์กฐํฉ์ ๋๋ฉด์ ๋ชจ์์ ๊ฐ์๋ฅผ ์๊ณ , ๋ ๋ฒ์งธ ์กฐ๊ฑด์ ๋ง์กฑํ๋์ง ์ฒดํฌํ ํ ์ถ๋ ฅํ๋๋ก ํ์ต๋๋ค. ์ ๋ ฅ ๋ฐ์ ๋๋ถํฐletters๋ฅผ ์ ๋ ฌํด์, ๋ณ๋์ ์ ๋ ฌ ์์ด ๋ฐ๋ก ์ฌ์ ์ ์ถ๋ ฅ์ด ๊ฐ๋ฅํ๊ฒ ํ์ต๋๋ค.๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ