1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paizaラーニング レベルアップ問題集 Aランクレベルアップメニュー JavaScript 盤面の情報変更

Last updated at Posted at 2022-09-20

盤面の情報変更

JavaScriptで解いてみました。

解答例

const fs = require("fs");
const input = fs.readFileSync("/dev/stdin", "utf-8").trim();
const lines = input.split("\n");
//盤面の行数を表す整数 H , 盤面の列数を表す整数 W , 与えられる座標の数を表す整数 N 
const [H,W,N] = lines[0].split(" ").map((num) => Number(num));
//盤面
const board = [];
for (let i = 1; i <= H; i++) {
    board.push(lines[i].split(""));
}
//盤面の与えられた座標の文字を "#" に書き換えた後の盤面を出力
for (let i = 1; i <= N; i++) {
    const [y,x] = lines[i + H].split(" ").map(Number);
    board[y][x] = "#";
}

console.log(board.map(row => row.join("")).join("\n"));

盤面はsliceでも書けます。

//盤面
const board = lines.slice(1, H + 1).map(line => line.split(""));
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?