• Home
  • About
    • Ryureka Moment photo

      Ryureka

      Sin Prisa, Sin Pausa

    • About Me
    • Facebook
    • Github
    • Youtube
  • Projects
  • Posts
    • Posts
    • ProblemSolvings
    • Tags
    • Blog
    • Examples
  • ProblemSolving
    • ProblemSolving
    • BOJ
    • Programmers
    • SWEA
    • LeetCode
  • FrontEnd
    • FrontEnd
    • HTML
  • BackEnd
    • BackEnd
    • Server
      • Server
      • Spring
      • NodeJS
    • DataBase
      • DataBase
      • MySQL
      • MongoDB
  • Programming
    • Programming
    • Java
    • JS
    • Python
    • CleanCode
  • ComputerScience
    • DataStructure
    • Algorithm

[BOJ] 6603. 로또

15 Apr 2026

Reading time ~1 minute

  • 풀이

풀이

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(true) {
			int k=sc.nextInt();
			if(k==0) break;
			int arr[]=new int[k];
			int copy[]=new int[6];
			for (int i = 0; i < k; i++) {
				arr[i]=sc.nextInt();
			}
			
			go(0,arr,copy,0);
			System.out.println();
		}
		
	}
	
	public static void go(int index,int arr[],int copy[],int cnt) {
		if(cnt==6) {
			for (int i = 0; i < copy.length; i++) {
				System.out.print(copy[i]+" ");
			}
			System.out.println();
			return;
		}
		if(index>=arr.length) return;
		copy[cnt]=arr[index];
		go(index+1,arr,copy,cnt+1);
		copy[cnt]=0;
		go(index+1,arr,copy,cnt);
	}
}


백트래킹조합재귀 Share