복습: 정수 센트
Coddy의 C# 개발자를 위한 PHP 코스 레슨. 48개 중 24번째.
챌린지
쉬움입력은 [prices,discount]이며, prices는 음수가 아닌 정수 센트이고 discount는 0..100입니다. discounted는 floor(total*(100-discount)/100)을 반환합니다. total은 최대 100000입니다.
제공된 main 스크립트는 표준 입력에서 JSON 값 하나를 읽고, 지정된 공개 API를 확인한 다음 결과를 출력합니다. 출력하지 않도록 모듈 선언을 구현하세요. 실행 파일을 대체하거나 모듈에서 입력을 읽지 마세요. 입력은 명시된 유형과 범위를 충족합니다.
Functions.php를 수정하세요. main.php는 잠긴 진입 파일입니다. 종속성에는 상대 파일 이름과 함께 require_once __DIR__를 사용합니다.
직접 해보기
<?php
declare(strict_types=1);
require_once __DIR__."/Functions.php";
function ensure(bool $ok,string $message):void{if(!$ok)throw new RuntimeException("API: ".$message);}
$input=json_decode(trim(stream_get_contents(STDIN)),true,512,JSON_THROW_ON_ERROR);
ensure(discounted([15],10)===13,"integer floor");
echo (string)discounted(...$input),"\n";
C# 개발자를 위한 PHP의 모든 레슨
직접 연습해 보세요: 온라인 PHP 컴파일러