본문 바로가기

Coding/백준

6603번 로또

 재귀 문제.

 시작점을 기준으로 6개씩 고르면 된다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <queue>
#include <vector>
 
using namespace std;
 
queue<int> LottoK;
queue<int> LottoS;
vector<int> vec;
int K,S;
int answer[6];
 
void solved(int num, int start, int cnt){
    
    if(cnt==6){
        for(int i=0;i<6;i++){
            cout << answer[i] << " ";
        }
        cout << endl;
        return;
    }
    else{
        for(int i=start;i<num;i++){
            answer[cnt]=vec[i];
            solved(num, i+1, cnt+1);
        }
    }
}
 
int main(){
    
    bool flag = true;
    
    while(flag){
        cin >> K;
        
        if(K==0){
            break;
        }
        
        LottoK.push(K);
        
        for(int i=0;i<K;i++){
            cin >> S;
            LottoS.push(S);
        }
    }
    
    while(!LottoK.empty()){
        int j=LottoK.front();
        LottoK.pop();
        
        vec=vector<int> (j,0);
        
        for(int i=0;i<j;i++){
            vec[i]=LottoS.front();
            LottoS.pop();
        }
        
        solved(j,0,0);
        cout << endl;
    }
}
 
cs

'Coding > 백준' 카테고리의 다른 글

1541번 잃어버린 괄호  (0) 2021.02.05
2798번 블랙잭  (0) 2021.01.20
4963번 섬의 개수  (0) 2021.01.13
2966번 찍기  (0) 2020.07.15
2858번 기숙사 바닥  (0) 2020.07.14