Language: C++

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

const (
	BLOCKED   = -1
	EMPTY     = 0
	QUEEN     = 1
	BOARD_DIM = 8
	QUEEN_NUM = 8
)

type Board struct {
	table [][]int
	dim   int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	board := NewBoard(BOARD_DIM)

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		row, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		col, err := nextInt(sc)
		if err != nil {
			panic(err)
		}
		board = board.Put(row, col)
	}

	_, result := eightQueens(2, board)

	for i := 0; i < board.dim; i++ {
		row := make([]string, board.dim)
		for j, v := range result.table[i] {
			if v == QUEEN {
				row[j] = "Q"
			} else {
				row[j] = "."
			}
		}
		fmt.Println(strings.Join(row, ""))
	}
}

func eightQueens(numQueens int, board *Board) (bool, *Board) {
	if numQueens == QUEEN_NUM {
		return true, board
	}
	for i := 0; i < BOARD_DIM; i++ {
		for j := 0; j < BOARD_DIM; j++ {
			if board.CanPut(i, j) {
				newBoard := board.Put(i, j)
				result, resultBoard := eightQueens(numQueens+1, newBoard)
				if result {
					return true, resultBoard
				}
			}
		}
	}
	return false, nil
}

func NewBoard(dim int) *Board {
	table := make([][]int, dim)
	for i := 0; i < dim; i++ {
		table[i] = make([]int, dim)
	}
	return &Board{table: table, dim: dim}
}

func CopyBoard(board *Board) *Board {
	dim := board.dim
	newBoard := NewBoard(dim)
	for i := 0; i < dim; i++ {
		for j := 0; j < dim; j++ {
			newBoard.table[i][j] = board.table[i][j]
		}
	}
	return newBoard
}

func (board *Board) IsEmpty(row int, col int) bool {
	return board.table[row][col] == EMPTY
}

func (board *Board) existsQueen(posX int, posY int, dirX int, dirY int) bool {
	dim := board.dim
	posX = posX + dirX
	posY = posY + dirY
	for 0 <= posX && posX < dim && 0 <= posY && posY < dim {
		if board.table[posX][posY] == QUEEN {
			return true
		}
		posX = posX + dirX
		posY = posY + dirY
	}
	return false
}

func (board *Board) CanPut(row int, col int) bool {
	if !board.IsEmpty(row, col) {
		return false
	}
	for dirX := -1; dirX < 1; dirX++ {
		for dirY := -1; dirY < 1; dirY++ {
			if dirX == 0 && dirY == 0 {
				continue
			}
			if board.existsQueen(row, col, dirX, dirY) {
				return false
			}
		}
	}
	return true
}

func (board *Board) Put(row int, col int) *Board {
	newBoard := CopyBoard(board)
	newBoard.table[row][col] = 1
	newBoard.fill(row, col, -1, -1)
	newBoard.fill(row, col, 0, -1)
	newBoard.fill(row, col, 1, -1)
	newBoard.fill(row, col, 1, 0)
	newBoard.fill(row, col, 1, 1)
	newBoard.fill(row, col, 0, 1)
	newBoard.fill(row, col, -1, 1)
	newBoard.fill(row, col, -1, 0)
	return newBoard
}

func (board *Board) fill(posX int, posY int, dirX int, dirY int) {
	dim := board.dim
	posX = posX + dirX
	posY = posY + dirY
	for 0 <= posX && posX < dim && 0 <= posY && posY < dim {
		board.table[posX][posY] = -1
		posX = posX + dirX
		posY = posY + dirY
	}
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}


Compiler output:
a.cc:1:1: error: 'package' does not name a type
    1 | package main
      | ^~~~~~~
a.cc:24:1: error: 'func' does not name a type
   24 | func main() {
      | ^~~~
a.cc:62:1: error: 'func' does not name a type
   62 | func eightQueens(numQueens int, board *Board) (bool, *Board) {
      | ^~~~
a.cc:80:1: error: 'func' does not name a type
   80 | func NewBoard(dim int) *Board {
      | ^~~~
a.cc:88:1: error: 'func' does not name a type
   88 | func CopyBoard(board *Board) *Board {
      | ^~~~
a.cc:99:6: error: expected constructor, destructor, or type conversion before '(' token
   99 | func (board *Board) IsEmpty(row int, col int) bool {
      |      ^
a.cc:103:6: error: expected constructor, destructor, or type conversion before '(' token
  103 | func (board *Board) existsQueen(posX int, posY int, dirX int, dirY int) bool {
      |      ^
a.cc:117:6: error: expected constructor, destructor, or type conversion before '(' token
  117 | func (board *Board) CanPut(row int, col int) bool {
      |      ^
a.cc:134:6: error: expected constructor, destructor, or type conversion before '(' token
  134 | func (board *Board) Put(row int, col int) *Board {
      |      ^
a.cc:148:6: error: expected constructor, destructor, or type conversion before '(' token
  148 | func (board *Board) fill(posX int, posY int, dirX int, dirY int) {
      |      ^
a.cc:159:1: error: 'func' does not name a type
  159 | func nextInt(sc *bufio.Scanner) (int, error) {
      | ^~~~