Night 23: A map for your pet
이미 Python 또는 의사 코드로 이날의 학습을 마쳤습니다. 두 언어 모두에서 완료한 것으로 인정됩니다. 원하면 다시 연습하세요.
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Tonight: a map for your pet
- Your pet's world needs a map: rows and columns, like a chess board.
- You will learn one thing: 2D arrays.
Words for tonight
| Word | Meaning |
|---|---|
| grid | rows and columns of boxes |
| row | a line from left to right |
| column | a line from top to bottom |
English
Two indexes
- A 2D array has a range for the rows and a range for the columns.
World[Row, Column]: first the row, then the column. Both start at 1.
DECLARE World : ARRAY[1:2, 1:3] OF STRING
World[1, 1] ← "tree"
World[1, 2] ← "grass"
World[1, 3] ← "pond"
World[2, 1] ← "grass"
World[2, 2] ← "home"
World[2, 3] ← "grass"
OUTPUT World[2, 2]
OUTPUT World[1, 3]

English
Fill and print the map
- Two loops can fill every place, and two more can print it.
DECLARE Grid : ARRAY[1:2, 1:3] OF STRING
DECLARE RowNumber, Col : INTEGER
DECLARE Row : STRING
FOR RowNumber ← 1 TO 2
FOR Col ← 1 TO 3
Grid[RowNumber, Col] ← "."
NEXT Col
NEXT RowNumber
Grid[2, 3] ← "P"
FOR RowNumber ← 1 TO 2
Row ← ""
FOR Col ← 1 TO 3
Row ← Row & Grid[RowNumber, Col]
NEXT Col
OUTPUT Row
NEXT RowNumber
English
Rows first
| Code | Means |
|---|---|
Grid[2, 3] |
row 2, column 3 |
Grid[3, 2] |
row 3, column 2: a different place! |
- In exams, the question always says which index is the row. Read it carefully.
- Now draw your pet's map!
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Here is your pet's world as a 2D array. Output the place at row 2, column 2, then the place at row 1, column 3. The output is home, then pond.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Put your pet P at row 3, column 1. Then output each row as one line, built with &. The last line is P...
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Count the trees T in the garden with a loop inside a loop. Output the count: 3.
출력을 보려면 '실행'을 클릭하세요.
난이도 4/5 · 280코인 + 오늘 첫 완료 시 작은 보너스 추가
Find where H (home) is. Use two loops and output its row and column: 2 3.
출력을 보려면 '실행'을 클릭하세요.