최종: 재고 포트
Coddy의 C# 개발자를 위한 GDScript 코스 레슨. 48개 중 47번째.
챌린지
쉬움C# 참조 구현을 포팅하세요. 입력 단어를 받아 알파벳순으로 정렬된 단어=count 쌍을 쉼표로 연결해 반환하거나, 단어가 없으면 none을 반환합니다. 단어는 소문자 ASCII이며 중복된 단어도 각각 셉니다. 호출자의 입력을 변경하지 마세요.
입력은 stdin으로 전달되는 JSON 배열 하나입니다. 잠긴 main은 배열을 파싱하고 공개 API를 호출한 다음, 반환된 텍스트 앞에 result=를 붙여 출력하고 줄바꿈 문자를 출력합니다. 보조 함수는 출력하면 안 됩니다. 독립적인 고정 프로브는 입력 사례를 처리하기 전에 필수 API 동작을 확인하며, 구현 방식을 제한하지는 않습니다.
완성된 C# 참조 구현입니다. 나열된 파일을 System.Web.Extensions 프레임워크 어셈블리와 함께 컴파일하세요. Program.Main은 동일한 JSON 배열을 읽고 동일한 결과 프로토콜에 따라 출력합니다. 이는 독립 실행형 C# 참조 구현이며, Godot C# 통합이 아닙니다.
C# 파일 Inventory.cs:
using System;
using System.Collections.Generic;
using System.Globalization;
public static class Inventory {
public static string Summarize(IEnumerable<string> words) {
var counts = new SortedDictionary<string,int>(StringComparer.Ordinal);
foreach (string word in words) {
int count;
counts.TryGetValue(word, out count);
counts[word] = count + 1;
}
var parts = new List<string>();
foreach (var pair in counts)
parts.Add(pair.Key + "=" + pair.Value.ToString(CultureInfo.InvariantCulture));
return parts.Count == 0 ? "none" : String.Join(",", parts);
}
}C# 파일 Program.cs:
using System;
using System.Web.Script.Serialization;
public static class Program {
public static void Main() {
var words = new JavaScriptSerializer().Deserialize<string[]>(Console.ReadLine());
Console.WriteLine("result=" + Inventory.Summarize(words));
}
}코드는 exercise.gd에 작성하세요. main.gd에는 제공된 입력/출력 코드가 있으며 수정할 수 없습니다. 각 class_name 형식은 지정된 파일에 두세요.
직접 해보기
extends Node
func contract_ok(data: Array) -> bool:
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 컴파일러