ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 1759 - 암호만들기
    백준 algorithm 2020. 6. 17. 15:44

    문제 설명 

     

     

    => 입력값의 범위가 작기 때문에 브루트 포스로 해결할 수 있습니다. 

     

     

    ** 본인이 작성한 코드에는 정렬의 과정이 표현되어있지 않기 때문에, 함수 진입 전에 alpha vector의 sort과정이 필요합니다. 

     

     

     

    <code>

    #include <iostream>
    #include <algorithm>
    #include <string>
    #include <vector>
    
    
    using namespace std;
    
    bool check(string &password)
    {
        int conso=0;
        int vowel=0;
        for(char x : password)
        {
            if(x == 'a' || x=='e' ||x=='i' || x == 'o' || x== 'u')
            {
                vowel ++;
            }
            else{
                conso++;
            }
        }
        return conso >= 2 && vowel >=1;
    }
    
    void go(int n, vector<char> &alpha, string password, int i)
    {
    if(password.length() == n)
    {
        if(check(password))
        {
            cout << password<<'\n';
        }
        return;
    }
        if(i >= alpha.size())return;
        go(n, alpha, password+alpha[i], i+1);
        go(n, alpha, password, i+1);
    }
    
    
    
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        
        int L, C;
        cin >> L >> C;
        vector<char> alpha;
        string password;
        int cnt =0;
        for(int i=0; i<C; i++)
        {
            char c;
            cin >> c;
            alpha.push_back(c);
        }
        sort(alpha.begin(), alpha.end());
        go(L, alpha, password, 0);
        return 0;
    }
    

     

     

     

    실행화면 1
    실행 화면 2

    '백준 algorithm' 카테고리의 다른 글

    백준 1260 -DFS와 BFS  (0) 2020.07.03
    백준 13023 - ABCDE  (0) 2020.07.03
    백준 2839 - 설탕 배달  (2) 2020.06.05
    백준 10973 - 이전 순열  (0) 2020.06.05
    백준 10972 - 다음 순열  (0) 2020.06.05

    댓글

Designed by Who.