Queens Combinations - 2d As 2d - Box Chooses

PHOTO EMBED

Thu Aug 04 2022 12:06:54 GMT+0000 (Coordinated Universal Time)

Saved by @Ayush_dabas07 #java

import java.io.*;
import java.util.*;

public class Main {

    public static void queensCombinations(int qpsf, int tq, int row, int col, String asf){
        
        if(row == tq){
            if(qpsf == tq)
            System.out.println(asf);
            
            return;
        }
        
        
        
        if(col == tq -1){
            row = row+1;
            col = -1;
            queensCombinations(qpsf + 1, tq , row , col+1 , asf+"q\n");
            queensCombinations(qpsf, tq , row , col+1 , asf+"-\n");
        }
        
        else{
            queensCombinations(qpsf + 1, tq , row , col+1 , asf+'q');
            queensCombinations(qpsf, tq , row , col+1 , asf+'-');
        }
    
    }
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        
        queensCombinations(0, n, 0, 0, "");
    }
}
content_copyCOPY