Language: C++

#include <iostream>
#include <map>

static const int BOARD_SIZE = 8;	// チェスボードの大きさ（縦横で同じ）

/* -------------------------------------------------------------------------- */
/* QueenCommand クラス                                                        */
/* -------------------------------------------------------------------------- */
class QueenCommand
{
public:
	QueenCommand();
	
	bool contains(int r, int c);
	void put_on(int r, int c);
	void take_off(int r, int c);

private:
	int to_dpos_idx(int r, int c)
	{
		return r + c;
	}

	int to_dneg_idx(int r, int c)
	{
		return r + (BOARD_SIZE - 1 - c);
	}

	/* 横, 右斜め、左斜めのクイーンの利き (true で利きがある) */
	bool column[BOARD_SIZE];		/* 横 */
	bool dpos[2 * BOARD_SIZE - 1];	/* 左下～右上に向かう方向の斜め（傾きが正なので pos） */
	bool dneg[2 * BOARD_SIZE - 1];	/* 左上～右下に向かう方向の斜め（傾きが負なので neg） */
};

/* -------------------------------------------------------------------------- */

QueenCommand::QueenCommand()
{
	for(int i = 0; i < BOARD_SIZE; i++)
	{
		column[i] = false;
	}
	for(int i = 0; i < 2 * BOARD_SIZE - 1; i++)
	{
		dpos[i] = dneg[i] = false;
	}
}

bool QueenCommand::contains(int r, int c)
{
	int dpos_idx = to_dpos_idx(r, c);
	int dneg_idx = to_dneg_idx(r, c);
	return ( column[c] || dpos[dpos_idx] || dneg[dneg_idx] );
}

void QueenCommand::put_on(int r, int c)
{
	int dpos_idx = to_dpos_idx(r, c);
	int dneg_idx = to_dneg_idx(r, c);
	column[c] = dpos[dpos_idx] = dneg[dneg_idx] = true;
}

void QueenCommand::take_off(int r, int c)
{
	int dpos_idx = to_dpos_idx(r, c);
	int dneg_idx = to_dneg_idx(r, c);
	column[c] = dpos[dpos_idx] = dneg[dneg_idx] = false;
}

/* -------------------------------------------------------------------------- */
/* Queen8 クラス                                                              */
/* -------------------------------------------------------------------------- */
class Queen8
{
public:
	Queen8();
	
	void set_initial_pos(int row, int column);
	void solve();
	void print();

private:
	/* メンバ関数 */
	void solve_recursive(int row);
	bool can_put(int row, int column)
	void put_on(int row, int column);
	void take_off(int row, int column);

	/* メンバ変数 */
	const int FREE;
	
	QueenCommand       command;
	std::map<int, int> pos;			// key=row, value=column
	std::map<int, int> initial_pos; // key=row, value=column
	std::map<int, int> answer;		// key=row, value=column
	bool               found;
};

/* -------------------------------------------------------------------------- */
Queen8::Queen8() : FREE(-1)
{
	found = false;
	for(int i = 0; i < BOARD_SIZE; i++)
	{
		pos[i]         = FREE;
		initial_pos[i] = FREE;
	}
}

void Queen8::set_initial_pos(int row, int column)
{
	initial_pos[row] = column;
}

void Queen8::solve()
{
	found = false;
	answer.clear();
	solve_recursive(0);
}

void Queen8::print()
{
	if( found )
	{
		for(int r = 0; r < BOARD_SIZE; r++)
		{
			int queen_column = answer[r];
			for(int c = 0; c < BOARD_SIZE; c++)
			{
				std::cout << ((queen_column == c) ? 'Q' : '.');
			}
			std::cout << std::endl;
		}
	}
}

void Queen8::solve_recursive(int row)
{
	if( found )
	{
		/* 既に探索完了済 */
		return;
	}

	if(row == BOARD_SIZE)	
	{
		/* 全列置いたので探索完了. やったねたえちゃん. */
		answer = pos;
		found  = true;
		return;
	}

	for(int column = 0; column < BOARD_SIZE; column++)	/* 全列総当りで */
	{
		if(can_put(row, column))						/* クイーンが置けるか判定する */
		{
			put_on(row, column);						/* 置けるなら置く */
			solve_recursive(row + 1);					/* 置いたら次の行のQueenへ */
			take_off(row, column);						/* 置いたQueenを戻す */
		}
	}
	
	return;
}

bool Queen8::can_put(int row, int column)
{
	/* 他の駒が利いている */
	if( command.contains(row, column) )
	{
		return false;
	}

	/* 最初に置いたクイーンにかぶる */
	if( (initial_pos[row] != FREE) && (initial_pos[row] != column) )
	{
		return false;
	}
	
	return true;
}

void Queen8::put_on(int row, int column)
{
	/* 置く */
	pos[row] = column;
	command.put_on(row, column);

	return true;
}

void Queen8::take_off(int row, int column)
{
	pos[row] = FREE;
	command.take_off(row, column);
}

/* -------------------------------------------------------------------------- */
/* It's main !!!                                                              */
/* -------------------------------------------------------------------------- */

int main()
{
	Queen8 q8;

	int k, r, c;
	std::cin >> k;
	
	for(int i = 0; i < k; i++)
	{
		std::cin >> r >> c;
		q8.set_initial_pos(r, c);
	}
	
	q8.solve();
	q8.print();
	
	return 0;
}




Compiler output:
a.cc:85:41: error: expected ';' at end of member declaration
   85 |         bool can_put(int row, int column)
      |                                         ^
      |                                          ;
a.cc: In member function 'void Queen8::put_on(int, int)':
a.cc:190:16: error: return-statement with a value, in function returning 'void' [-fpermissive]
  190 |         return true;
      |                ^~~~