Menu
CoddyTech

창고: 보고서

Coddy의 C++ 개발자를 위한 GDScript 코스 레슨. 48개 중 44번째.

challenge icon

챌린지

쉬움

add는 유지하세요. report를 구현하세요: 0을 포함하여 ASCII 순으로 정렬된 name=quantity 쌍을 쉼표로 구분하며, 비어 있는 창고는 "none"을 반환합니다. 입력은 stage, command 배열, 그리고 4단계에서는 price 딕셔너리입니다. 명령은 [add or take,name,quantity] 형식입니다. solve는 이 단계에서 사용 가능한 작업만 분기하여 실행합니다. 레이아웃과 잠긴 main은 프로젝트 전체에서 변경되지 않고 유지됩니다. 새로 요구되는 StockDepot 메서드만 완성하세요.

입력은 stdin의 JSON 배열 하나입니다. 잠긴 main이 이를 파싱하여 공개 API를 호출하고, "result=" 뒤에 반환된 텍스트와 줄바꿈을 출력합니다. 어떤 헬퍼도 출력해서는 안 됩니다. 입력 케이스 전에 독립적인 고정 검증 코드(probe)가 필수 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))

C++ 개발자를 위한 GDScript의 모든 레슨

직접 연습해 보세요: 온라인 GDScript 컴파일러