창고: 보고서
Coddy의 PHP 개발자를 위한 GDScript 코스 레슨. 48개 중 44번째.
챌린지
쉬움add는 그대로 둡니다. report를 구현하세요. 0을 포함한 name=quantity 쌍을 ASCII 기준으로 정렬하고 쉼표로 구분해 반환합니다. depot이 비어 있으면 none을 반환합니다. 입력은 stage, command 배열이며, 네 번째 단계에서는 price 사전도 포함됩니다. 명령은 [add 또는 take,name,quantity]입니다. solve는 해당 단계에서 사용할 수 있는 작업만 전달합니다. 프로젝트 전체에서 레이아웃과 잠긴 main은 변경하지 않습니다. 새로 필요한 StockDepot 메서드만 완성하세요.
입력은 stdin에 제공되는 단일 JSON 배열입니다. 잠긴 main은 입력을 파싱하고, 공개 API를 호출한 뒤 result= 다음에 반환된 텍스트와 줄바꿈을 출력합니다. 어떤 도우미 함수도 출력하면 안 됩니다. 입력 사례를 처리하기 전에 독립적인 고정 프로브가 필수 API 동작을 검증하며, 구현 방식은 제한하지 않습니다.
코드는 stock_depot.gd, exercise.gd에 작성하세요. main.gd에는 제공된 입력/출력 코드가 있으며 수정할 수 없습니다. 각 class_name 유형은 이름이 지정된 파일에 두세요.
직접 해보기
extends Node
func contract_ok(data: Array) -> bool:
var stage: int = int(data[0])
var depot: StockDepot = StockDepot.new()
if depot.add("",2) or depot.add("p",-1): return false
if not depot.add("p",3) or not depot.add("p",2): return false
if stage >= 2 and depot.report() != "p=5": return false
if stage >= 3:
if depot.take("p",6) or depot.take("q",0) or depot.take("p",-1): return false
if depot.report() != "p=5" or not depot.take("p",2) or depot.report() != "p=3": return false
if stage >= 4 and depot.worth({"p":4}) != 12: return false
return true
func _ready() -> void:
var data: Array = JSON.parse_string(OS.read_string_from_stdin())
if not contract_ok(data):
print("API_CONTRACT_FAILED")
return
print("result=" + Exercise.solve(data))
PHP 개발자를 위한 GDScript의 모든 레슨
직접 연습해 보세요: 온라인 GDScript 컴파일러