Menu
CoddyTech

복습: 충전 게이트

Coddy의 C# 개발자를 위한 Dart 코스 레슨. 48개 중 11번째.

challenge icon

챌린지

쉬움

charge(int initial,List<int> costs)를 구현하세요. 요청을 순서대로 적용하고, 현재 충전량 이하인 비용만 지불한 다음 remaining:accepted를 반환하세요. 모든 입력 정수는 0 이상 100 이하입니다. 첫 번째 정수는 초기 충전량이며, 비용이 0인 요청도 수락한 것으로 계산합니다.

편집 가능한 파일에서 출력하지 마세요. 제공된 exercise.dart는 입력을 파싱하고 출력을 반환합니다. 잠금된 드라이버는 공개 API를 별도로 테스트하고 결과를 줄바꿈 문자 하나와 함께 출력합니다.

코드는 functions.dart, exercise.dart에 작성하세요. main.dart에는 제공된 입력/출력 코드가 있으며 수정할 수 없습니다.

직접 해보기

import 'dart:io';
import 'dart:convert';
import 'exercise.dart';
import 'functions.dart';
void check(bool condition){if(!condition)throw StateError('Public API contract failed');}
Future<void> main() async {
final raw=await stdin.transform(utf8.decoder).join();
final input=raw.replaceFirst(RegExp(r'\r?\n$'),'');
check(charge(6,[7,2,4])=='0:2');
stdout.writeln(solve(input));
}

C# 개발자를 위한 Dart의 모든 레슨

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