Queens (3)

Write a program to print the lexicographically smallest way to place n
queens on an n × n chessboard so that no queen threatens another queen.

Input

Input consists of a natural number n > 0.

Output

Mark the queens with a ‘Q’, and the empty positions with a dot. Print
the lexicographically smallest way (by rows, from top to bottom, and
assuming that a ‘Q’ is smaller than a dot) to place n queens on an n × n
chessboard so that no queen threatens another queen. If there is no
solution, print “NO SOLUTION”.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:36:24.478Z

© Jutge.org, 2006–2026.
https://jutge.org
