PHP (Legacy)

No description

fork
loading
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

error_reporting(-1);

$amount = 54500;

$bills = [
    100 => 100,
    200 => 100,
    500 => 100,
    1000 => 100,
    2000 => 100,
    5000 => 100
];

$count100 = 0;
$count200 = 0;
$count500 = 0;
$count1000 = 0;
$count2000 = 0;
$count5000 = 0;

for ($i = 0; $amount > 0 ; $i++) {
    $minus5000 = $amount - 5000;
    $minus2000 = $amount - 2000;
    $minus1000 = $amount - 1000;
    $minus500 = $amount - 500;
    $minus200 = $amount - 200;
    $minus100 = $amount - 100;
    if (($minus5000 >= 0)&&($bills[5000]>0)){
        $amount -= 5000;
        $count5000 ++;
        $bills[5000] --;
    }elseif (($minus5000 >= 0)&&($bills[5000]>0)) {
        $amount -= 2000;
        $count2000 ++;
        $bills[2000] --;
    }elseif (($minus1000 >= 0)&&($bills[1000] > 0)) {
        $amount -= 1000;
        $count1000 ++;
        $bills[1000] --;
    }elseif (($minus500 >= 0)&&($bills[500] > 0)) {
        $amount -= 500;
        $count500 ++;
        $bills[500] --;
    }elseif (($minus200 >= 0)&&($bills[200] > 0)) {
        $amount -= 200;
        $count200 ++;
        $bills[200] --;
    }elseif (($minus100 >= 0)&&($bills[100] > 0)) {
        $amount -= 100;
        $count100 ++;
        $bills[100] --;
    }else {
        echo "Выдача невозможна: недостаточно купюр";
        exit();
    }
}

echo "Выдача возможна, число купюр:\n{$count100}x100 {$count200}x200 {$count500}x500 {$count1000}x1000 {$count2000}x2000 {$count5000}x5000";

?>
PHP 7.0.8 (Legacy: use the following for new features: Command-line PHP: https://repl.it/languages/php_cli PHP Web Server: https://repl.it/languages/php7