teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

文法の修正

2019/04/12 05:35

投稿

norikr
norikr

スコア10

title CHANGED
File without changes
body CHANGED
@@ -35,7 +35,36 @@
35
35
  ### 該当のソースコード
36
36
 
37
37
  ```php
38
+ public function getBillCount(int $bill): ?array
39
+ {
40
+ $count_1 = $bill%5;
41
+ $count_5 = floor(($bill%10)/5);
42
+ $count_10 = floor(($bill%50)/10);
43
+ $count_50 = floor(($bill%100)/50);
44
+ $count_100 = floor(($bill%500)/100);
45
+ $count_500 = floor(($bill%1000)/500);
46
+ $count_1000 = floor(($bill%5000)/1000);
47
+ $count_5000 = floor(($bill%10000)/5000);
48
+ $count_10000 = floor($bill/10000);
49
+
50
+ $num = array (
51
+ "1" => $count_1,
52
+ "5" => $count_5,
53
+ "10" => $count_10,
54
+ "50" => $count_50,
55
+ "100" => $count_100,
56
+ "500" => $count_500,
57
+ "1000" => $count_1000,
58
+ "5000" => $count_5000,
59
+ "10000" => $count_10000,
60
+ );
61
+
62
+ return $num;
63
+ }
64
+
65
+ public function testGetBillCount_0枚有り()
66
+ {
38
- if ($count_1=$count_5=$count_10=$count_50=$count_100=$count_500=$count_1000=$count_5000=$count_10000 !== 0) {
67
+ if ($count_1=$count_5=$count_10=$count_50=$count_100=$count_500=$count_1000=$count_5000=$count_10000 !== 0) {
39
68
  $num = array (
40
69
  "1" => $count_1,
41
70
  "5" => $count_5,
@@ -47,6 +76,8 @@
47
76
  "5000" => $count_5000,
48
77
  "10000" => $count_10000,
49
78
  );
79
+ }
80
+
50
81
  ```
51
82
 
52
83
 

2

code機能の利用

2019/04/12 05:35

投稿

norikr
norikr

スコア10

title CHANGED
File without changes
body CHANGED
@@ -34,6 +34,7 @@
34
34
 
35
35
  ### 該当のソースコード
36
36
 
37
+ ```php
37
38
  if ($count_1=$count_5=$count_10=$count_50=$count_100=$count_500=$count_1000=$count_5000=$count_10000 !== 0) {
38
39
  $num = array (
39
40
  "1" => $count_1,
@@ -46,6 +47,7 @@
46
47
  "5000" => $count_5000,
47
48
  "10000" => $count_10000,
48
49
  );
50
+ ```
49
51
 
50
52
 
51
53
 

1

書式の改善

2019/04/12 05:30

投稿

norikr
norikr

スコア10

title CHANGED
File without changes
body CHANGED
@@ -5,11 +5,11 @@
5
5
  現在PHPの練習として以下の問題を解いているのですが、
6
6
  0以外の整数のみ配列に格納するにはどうすればいいのでしょうか、、?
7
7
 
8
- **Q.
8
+ **Q.**
9
- 入力された値から、各硬貨・紙幣の枚数を配列に格納する。
9
+ **入力された値から、各硬貨・紙幣の枚数を配列に格納する。**
10
- 配列の内容は、硬貨・紙幣の金額をKeyにして枚数を値にする。
10
+ **配列の内容は、硬貨・紙幣の金額をKeyにして枚数を値にする。**
11
- 枚数が0枚のものは、配列に格納しない。
11
+ **枚数が0枚のものは、配列に格納しない。**
12
- また、配列には金額の小さいものから順に並んでいる必要がある。**
12
+ **また、配列には金額の小さいものから順に並んでいる必要がある。**
13
13
 
14
14
 
15
15