Skip to content

Instantly share code, notes, and snippets.

@KaitoMuraoka
Created July 8, 2023 05:37
Show Gist options
  • Save KaitoMuraoka/c1461f49a2558bf34e9ddaf746081ae1 to your computer and use it in GitHub Desktop.
Save KaitoMuraoka/c1461f49a2558bf34e9ddaf746081ae1 to your computer and use it in GitHub Desktop.
Standard input given a board (n x m のマス目が与えられた時の標準入力)
private func readStringArray(_ count: Int) -> [[Character]] {
return (1...count).map { _ in
let value = Array(readLine()!)
return Array<Character>(value)
}
}
 //example:
//
//count = 3
//.....
//.#.#.
//.....
// outPut:
//[[".", ".", ".", ".", "."], [".", "#", ".", "#", "."], [".", ".", ".", ".", "."]]
@KaitoMuraoka
Copy link
Author

KaitoMuraoka commented Jul 8, 2023

概要

競技プログラミングとかである、「H×W のマス目」が標準入力で与えられた場合の処理関数を作成しました。
マス目を入力すると二重配列で出力されます。
countには列の数を入れてください。

3 x 5のマス目

.....
.#.#.
.....

がある場合、countは3になります。
これを入力すると以下のような二重配列の形で出力されます。

[[".", ".", ".", ".", "."], [".", "#", ".", "#", "."], [".", ".", ".", ".", "."]]

What is this?

I have created a function that handles the case where the "H x W squares" are given as standard input, which is competition programming or something like that.
When the squares are entered, they are output as a double array.
The count should be the number of columns.

Example

3 x 5 squares

.....
.#.#.
.....

is present, the count is 3.
If you type this in, the output will be in the form of a double array as follows.

[["." , "." , "." , "." , "."] , ["." , "#", "." , "#", "."] , ["." , "." , "." , "." , "."]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment