0
0

More than 1 year has passed since last update.

paizaラーニング レベルアップ問題集 新・Bランクレベルアップメニュー JavaScript 【マップの扱い 1】マップの書き換え・1 マス

Posted at

【マップの扱い 1】マップの書き換え・1 マス (paizaランク C 相当)

解答例

slice,map,joinを使いました。

const fs = require("fs");
const input = fs.readFileSync("/dev/stdin", "utf-8").trim();
const lines = input.split("\n");
//盤面の行数を表す整数 H , 盤面の列数を表す整数 W 
const [H, W] = lines[0].split(" ").map(Number);
//盤面の i 行目の文字をまとめた文字列 S
const S = lines.slice(1, H + 1).map(line => line.split(""));

//文字を書き換えるマスの y , x 座標
const [y, x] = lines[H + 1].split(" ").map(Number);

if (S[y][x] === ".") {
  S[y][x] = "#";
} else {
  S[y][x] = ".";
}

console.log(S.map(row => row.join("")).join(("\n")));
0
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
0
0