ホームページ >バックエンド開発 >PHPチュートリアル >ソフトウェアエンジニアリングペアリング課題 02

ソフトウェアエンジニアリングペアリング課題 02

WBOY
WBOYオリジナル
2016-06-13 12:29:131120ブラウズ

ソフトウェアエンジニアリングペアリング課題 02

1. 設計アイデア:

このタスクの主要な関数を実装するには、デフォルトでは加算と減算が必要です。含まれること。 まず、index.php

ファイルを作成し、HTML ステートメントでフォームを作成します。質問の数、最大値と最小値、その他のオプションが含まれます。 次に、rubric.php

ファイルを作成し、このファイルにフォーム情報を送信し、四則演算メソッドの実装時に渡された値を呼び出します。四則演算の実装方法は、以前に何度か Java を使用したときに使用した方法と同様であり、コードが修正および最適化されています。後で使用できるように、質問と回答をそれぞれ question.txt ファイルと answer.txt ファイルに保存します。 3 番目に、submitAnswer.php

acceptAnswer.phpdeleteAnswer php を作成します。 および judgeAnswer.php ファイルは、それぞれオンラインでの回答の送信、回答の受信、回答の削除、および回答の判断に使用されます。送信された回答は、answer1.txt ファイルに配置されます。回答は、answer.txtanswer1.txt ファイルの内容で十分です。 2. ソースプログラムコード

<span style="color: #008080;"> 1</span> インデックス.<span style="color: #000000;">php</span><span style="color: #008080;"> 2</span> <!DOCTYPE html><span style="color: #008080;"> 3</span> <!--<span style="color: #008080;"> 4</span> 開始 <span style="color: #008080;">日付</span> 2016/3/28<span style="color: #008080;"> 5</span> 完了 <span style="color: #008080;">日付</span> 2016/4/7<span style="color: #008080;"> 6 </span> <span style="color: #000000;">作者 Jing</span><span style="color: #008080;"> 7</span> <span style="color: #000000;">このプログラムは四則演算に関するものです</span><span style="color: #008080;"> 8</span> --><span style="color: #008080;"> 9</span> &lt ;html><span style="color: #008080;"> 10</span> <head><span style="color: #008080;"> 11</span> <meta charset="UTF-8"><span style="color: #008080;"> 12</span> <title>四則演算問題システム< /title><span style="color: #008080;"> 13</span> <script><span style="color: #008080;"> 14</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> check() {</span><span style="color: #008080;"> 15</span> <span style="color: #0000ff;">var </span> tt=/^(0|[1-9]d*)$/<span style="color: #000000;">;</span><span style="color: #008080;"> 16</span> <span style="color: #0000ff;">if</span>(!tt.test(form1.< 🎜) >min<span style="color: #008080;">.</span>value))<span style="color: #000000;"></span> 17<span style="color: #008080;"> </span> {<span style="color: #000000;"></span> 18<span style="color: #008080;"> alter('入力された最小値は不正です'</span>) ;<span style="color: #000000;"></span> 19<span style="color: #008080;"> form1.</span>min<span style="color: #008080;">.</span>focus();<span style="color: #000000;"></span> 20<span style="color: #008080;"> </span>return<span style="color: #0000ff;"> </span>false<span style="color: #0000ff;"></span>;<span style="color: #000000;"></span> 21<span style="color: #008080;"> </span> }<span style="color: #000000;"></span> 22<span style="color: #008080;"> </span>if<span style="color: #0000ff;">(!tt.test(form1.</span>max<span style="color: #008080;">.value) || (form1.</span>max<span style="color: #008080;">.value<form1.</span>min<span style="color: #008080;">.</span>value))<span style="color: #000000;"></span> 23<span style="color: #008080;"> </span> { <span style="color: #000000;"></span> 24<span style="color: #008080;">alert('最大値の入力が不正です'</span>);<span style="color: #000000;"></span> 25<span style="color: #008080;"> form1.</span>min<span style="color: #008080;">.</span>focus( ) ;<span style="color: #000000;"></span> 26<span style="color: #008080;"> </span>return<span style="color: #0000ff;"> </span>false<span style="color: #0000ff;"></span>;<span style="color: #000000;"></span> 27<span style="color: #008080;"> </span> }<span style="color: #000000;"></span> 28 <span style="color: #008080;"> </span>if<span style="color: #0000ff;">(!tt.test(form1.num.value) || (form1.num.value==0</span>))<span style="color: #000000;"></span> 29<span style="color: #008080;"> </span> {<span style="color: #000000;"></span> 30<span style="color: #008080;">alert('入力された質問の数が不正です'</span>);<span style="color: #000000;"></span> 31<span style="color: #008080;"> form1.num.</span>focus(); <span style="color: #000000;"></span> 32<span style="color: #008080;"> </span>return<span style="color: #0000ff;"> </span>false<span style="color: #0000ff;"></span>;<span style="color: #000000;"></span> 33<span style="color: #008080;"> </span> }<span style="color: #000000;"></span> 34<span style="color: #008080;"> </span>return<span style="color: #0000ff;"> </span>true<span style="color: #0000ff;"></span>;<span style="color: #000000;"></span> 35<span style="color: #008080;"> </span> }</span><span style="color: #008080;"> 36</span> </script><span style="color: #008080;"> 37</span> </head><span style="color: #008080;"> 38</span> <body background="2.jpg"><span style="color: #008080;"> 39 </span> <button type="button">ログイン</button>   <button type="button">登録</button><span style="color: #008080;"> 40</span> <br/ > <br/> <span style="color: #008080;"> 41</span> <center><span style="color: #008080;"> 42</span> <font color="red" size="7" face="毷体">小学校へようこそ 4算術演算質問システム</font> <br/><br/><br/><span style="color: #008080;"> 43</span> <span style="color: #008080;"> 44</span> <form action="rubric. php" target="_blank" method="post" name="form1" onsubmit="return check()" ><span style="color: #008080;"> 45</span> <font color="red" size="5">default 加算と2 つの数値のみを含む減算</font> <br/><br/><span style="color: #008080;"> 46</span> <span style="color: #008080;"> 47</span> <font color="blue" size ="4">操作に必要な最小値 (負ではない整数) を入力してください</font><span style="color: #008080;"> 48</span> <input type="text" name="min" /> br/><span style="color: #008080;"> 49</span> <span style="color: #008080;"> 50</span> <font color="blue" size="4">操作に関係する最大値を入力してください (負でない整数、および未満ではありません)最小値より)</font><span style="color: #008080;"> 51</span> <input type="text" name="max" /> <br/><br/><span style="color: #008080;"> 52</span> <span style="color: #008080;"> 53</span> <font color="blue" size="4">質問の数 (正の整数) を入力してください</font><span style="color: #008080;"> 54</span> <入力タイプ=" text" name="num" /> <br/><br/><span style="color: #008080;"> 55</span> <span style="color: #008080;"> 56</span> <font color="blue" size="4 "&gt ;操作に参加する番号の数を選択してください</font><span style="color: #008080;"> 57</span> <input type="radio" value="2" name="num1" selected />2<span style="color: #008080;"> 58</span> <input type="radio" value="3" name="num1" />3<span style="color: #008080;"> 59</span> <input type="radio" value="4" name="num1 " />4 <br>gt;<br><!--num1 の 1 ビットは 1 2 3 であり、l m n の l ではありません--><span style="color: #008080;"> 60</span> <span style="color: #008080;"> 61</span> <font color="blue" size="4">乗算を追加するかどうかを選択</font><span style="color: #008080;"> 62</span> <input type="radio" value="t" name="mul " /><span style="color: #000000;">はい</span><span style="color: #008080;"> 63</span> <input type="radio" value="f" name="mul" チェック済み />いいえ<br/> <br /><span style="color: #008080;"> 64</span> <span style="color: #008080;"> 65</span> <font color="blue" size="4">分割を追加するかどうかを選択してください</font><span style="color: #008080;"> 66</span> <input type="radio" value="t" name="div" /><span style="color: #000000;"> は </span><span style="color: #008080;"> 67</span> <input type="radio" value="f" name ="div " チェック済み />いいえ<br/><br/><span style="color: #008080;"> 68</span> <span style="color: #008080;"> 69</span> <input type="submit" value="確認" name=" send" /><span style="color: #008080;"> 70</span> <input type="reset" value="Reset" name="send" /><span style="color: #008080;"> 71</span> </form><span style="color: #008080;"> 72</span> </center><span style="color: #008080;"> 73</span> </body><span style="color: #008080;"> 74</span> </html><span style="color: #008080;"> 75</span> <span style="color: #008080;"> 76</span> ルーブリック<span style="color: #000000;"> php </span><span style="color: #008080;"> 77</span> <span style="color: #008080;"> 78</span> <html><span style="color: #008080;"> 79</span> <head><span style="color: #008080;"> 80</span> <meta charset="UTF-8" &gt ;<span style="color: #008080;"> 81</span> <title>質問設定インターフェース</title><span style="color: #008080;"> 82</span></head><span style="color: #008080;"> 83</span> <body bgcolor="LightCyan"><span style="color: #008080;"> 84</span> <span style="color: #008080;"> 85</span> <?<span style="color: #000000;">php</span><span style="color: #008080;"> 86 </span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">is_numeric</span>(<span style="color: #800080;">$_POST</span>["max"<span style="color: #000000;">]))</span><span style="color: #008080;"> 87</span> <span style="color: #000000;"> {</span><span style="color: #008080;"> 88</span> <span style="color: #800080;">$max</span>=<span style="color: #800080;">$_POST</span>["max"] <span style="color: #008000;">//</span><span style="color: #008000;">最大値</span>; <span style="color: #008080;"> 89</span> <span style="color: #000000;"> }</span><span style="color: #008080;"> 90</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">is_numeric</span>(<span style="color: #800080;">$_POST</span>["min"<span style="color: #000000;">]))</span><span style="color: #008080;"> 91</span> <span style="color: #000000;"> {</span><span style="color: #008080;"> 92</span> <span style="color: #800080;">$min</span>=<span style="color: #800080;">$_POST</span>["分" ]; <span style="color: #008000;">//</span><span style="color: #008000;">最小値</span><span style="color: #008080;"> 93</span> <span style="color: #000000;"> }</span><span style="color: #008080;"> 94</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;"> is_numeric</span>(<span style="color: #800080;">$_POST</span>["num"<span style="color: #000000;">]))</span><span style="color: #008080;"> 95</span> <span style="color: #000000;"> {</span><span style="color: #008080;"> 96</span> <span style="color: #800080;"> $num</span>=<span style="color: #800080;">$_POST</span>["num"]; <span style="color: #008000;">//</span><span style="color: #008000;">質問数</span><span style="color: #008080;"> 97</span> <span style="color: #000000;"> }</span><span style="color: #008080;"> 98</span> <span style="color: #0000ff;">if</span>(<span style="color: #008080;">is_numeric</span>(<span style="color: #800080;">$_POST</span>["num1"<span style="color: #000000;">]))</span><span style="color: #008080;"> 99</span> <span style="color: #000000;"> {</span><span style="color: #008080;">100</span> <span style="color: #800080;">$num1</span>=<span style="color: #800080;">$_POST</span>["num1"];操作に参加しているアイテムの数<span style="color: #008000;"></span>101<span style="color: #008000;"> </span> }<span style="color: #008080;"></span>102<span style="color: #000000;"> </span>if<span style="color: #008080;">(</span>is_string<span style="color: #0000ff;">(</span> $_POST <span style="color: #008080;">["mul"</span>]))<span style="color: #800080;"></span>103<span style="color: #000000;"> </span> {<span style="color: #008080;"></span>104<span style="color: #000000;"> </span>$mul<span style="color: #008080;">=</span>$ _POST<span style="color: #800080;">["mul"]; </span>//<span style="color: #800080;"></span>乗算を追加するかどうかを選択 Yes t No f<span style="color: #008000;"></span>105<span style="color: #008000;"> </span> }<span style="color: #008080;"></span>106 <span style="color: #000000;"> </span>if<span style="color: #008080;">(</span>is_string<span style="color: #0000ff;">(</span>$_POST<span style="color: #008080;">["div"</span>]))<span style="color: #800080;"></span>107<span style="color: #000000;"> </span> {<span style="color: #008080;"></span>108<span style="color: #000000;"> </span>$div<span style="color: #008080;">=</span>$_POST<span style="color: #800080;">["div"] </span>//<span style="color: #800080;"></span>除算を追加するには、yes tNof<span style="color: #008000;"></span>109<span style="color: #008000;"> </span> }</span><span style="color: #008080;">110</span> <span style="color: #008080;">111</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 配列 </span><span style="color: #008000;">*/</span><span style="color: #008080;">112</span> <span style="color: #800080;">$a</span>=<span style="color: #0000ff;">array</span>(); <span style="color: #008000;">//</span><span style="color: #008000;"> 乱数と演算子を格納するメソッドで使用されます</span><span style="color: #008080;">113</span> <span style="color: #800080;">$amd</span>=<span style="color: #0000ff;">array</span>(); <span style="color: #008000;">//</span><span style="color: #008000;"> は、乗除算の計算をこの配列に格納するメソッドで使用されます</span><span style="color: #008080;">114 </span> <span style="color: #800080;">$b</span>=<span style="color: #0000ff;">array</span>(); <span style="color: #008000;">//</span><span style="color: #008000;"></span><span style="color: #008080;">115</span> <span style="color: #800080;">$d</span>=<span style="color: #0000ff;">配列</span>(); <span style="color: #008000;">//</span><span style="color: #008000;">ストレージの質問</span><span style="color: #008080;">116</span> <span style="color: #800080;">$e</span>= <span style="color: #0000ff;">配列</span>(); <span style="color: #008000;">//</span><span style="color: #008000;">ストア回答</span><span style="color: #008080;">117</span> <span style="color: #008080;">118</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 結果クラスが使用されます結果をカプセル化する</span><span style="color: #008000;">*/</span><span style="color: #008080;">119</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> Result</span><span style="color: #008080;">120</span> <span style="color: #000000;"> { </span> <span style="color: #008080;">121</span> <span style="color: #0000ff;">public</span> <span style="color: #800080;">$r1</span>; <span style="color: #008000;">//</span><span style="color: #008000;">$r1 には計算結果が格納されます</span><span style="color: #008080;">122</span> <span style="color: #000000;"> }</span><span style="color: #008080;">123</span> <span style="color: #008080;">124</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 演算子には加算メソッドと減算メソッドのみがあります </span><span style="color: #008000;">*/</span><span style="color: #008080;">125 </span> <span style="color: #0000ff;">function</span> addSub(<span style="color: #800080;">$min</span>,<span style="color: #800080;">$max</span>,<span style="color: #800080;">$num1</span>,<span style="color: #800080;">$result</span><span style="color: #000000;"> )</span><span style="color: #008080;">126</span> <span style="color: #000000;"> {</span><span style="color: #008080;">127</span> <span style="color: #800080;">$str</span>=<span style="color: #008080;">mt_rand</span>(<span style="color: #800080;">$min</span> ,<span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;">128</span> <span style="color: #800080;">$re</span>=<span style="color: #800080;">$str</span><span style="color: #000000;">;</span><span style="color: #008080;">129</span> <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=1;<span style="color: #800080;">$i</span><<span style="color: #800080;">$num1</span>;<span style="color: #800080;">$i</span> <span style="color: #000000;">)</span><span style="color: #008080;">130</span> <span style="color: #000000;"> {</span><span style="color: #008080;">131</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span>]= <span style="color: #008080;">mt_rand</span>(<span style="color: #800080;">$min</span>,<span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;">132</span> <span style="color: #800080;">$c</span>=<span style="color: #008080;"> mt_rand</span>(0,1<span style="color: #000000;">);</span><span style="color: #008080;">133</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$c</span>==0<span style="color: #000000;">)</span><span style="color: #008080;">134</span> <span style="color: #000000;"> {</span><span style="color: #008080;">135</span> <span style="color: #800080;">$str</span>=<span style="color: #800080;">$str</span>." ".<span style="color: #800080;">$a</span>[ <span style="color: #800080;">$i</span><span style="color: #000000;">];</span><span style="color: #008080;">136</span> <span style="color: #800080;">$re</span>=<span style="color: #800080;">$re</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span><span style="color: #000000;">];</span><span style="color: #008080;">137</span> <span style="color: #000000;"> }</span><span style="color: #008080;">138</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$c</span>==1<span style="color: #000000;">)</span><span style="color: #008080;">139</span> <span style="color: #000000;"> {</span><span style="color: #008080;">140</span> <span style="color: #800080;">$str</span>=<span style="color: #800080;">$str</span> ." - ".<span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span><span style="color: #000000;">];</span><span style="color: #008080;">141</span> <span style="color: #800080;">$re</span>=<span style="color: #800080;">$ re</span>-<span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span><span style="color: #000000;">];</span><span style="color: #008080;">142</span> <span style="color: #000000;"> }</span><span style="color: #008080;">143</span> <span style="color: #000000;"> }</span><span style="color: #008080;">144</span> <span style="color: #800080;">$result</span>->r1=<span style="color: #800080;">$re</span><span style="color: #000000;">;</span><span style="color: #008080;">145</span> <span style="color: #800080;">$str</span>=<span style="color: #800080;">$str</span>." = "<span style="color: #000000;">;</span><span style="color: #008080;">146</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$str</span> <span style="color: #000000;">;</span><span style="color: #008080;">147</span> <span style="color: #000000;"> }</span><span style="color: #008080;">148</span> <span style="color: #008080;">149</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 演算子は加算、減算、乗算のメソッドです </span><span style="color: #008000;">*/</span><span style="color: #008080;"> 150</span> <span style="color: #0000ff;">function</span> addSubMul(<span style="color: #800080;">$min</span>,<span style="color: #800080;">$max</span>,<span style="color: #800080;">$num1</span>,<span style="color: #800080;">$result</span><span style="color: #000000;">)</span><span style="color: #008080;">151</span> <span style="color: #000000;"> {</span><span style="color: #008080;">152</span> <span style="color: #800080;">$a</span>[0]= <span style="color: #008080;">mt_rand</span>(<span style="color: #800080;"> $ min</span>, <span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;">153</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 計算内の数値と演算子をarray $a </span><span style="color: #008000;">*/</span><span style="color: #008080;">154</span> <span style="color: #008000;">/*</span><span style="color: #008000;">このループ内で演算子の左側と右側にスペースを追加すると、次の while ループ内 if 条件文の演算子でもスペースを追加する必要があります。追加しないとエラーが発生します </span><span style="color: #008000;">*/</span><span style="color: #008080;">155</span> <span style="color: #0000ff;">for</span>(<🎜) >$i<span style="color: #800080;"> =1;</span>$i<span style="color: #800080;"><(2*</span>$num1<span style="color: #800080;">-1);</span>$i<span style="color: #800080;">=</span>$i<span style="color: #800080;"> 2) </span> //<span style="color: #008000;"></span>(2*$num1-1) は、計算に含まれる数値と演算子の合計です <span style="color: #008000;"></span>156<span style="color: #008080;"> </span> {<span style="color: #000000;"></span> 157<span style="color: #008080;"> </span>$c<span style="color: #800080;">= </span>mt_rand<span style="color: #008080;">(0, 2</span>);<span style="color: #000000;"></span>158<span style="color: #008080;"> </span>if<span style="color: #0000ff;"> (</span> $c<span style="color: #800080;">==0</span>)<span style="color: #000000;"></span>159<span style="color: #008080;"> </span> {<span style="color: #000000;"></span>160<span style="color: #008080;"> </span>$a<span style="color: #800080;">[</span>$i <span style="color: #800080;">]=' '</span>;<span style="color: #000000;"></span>161<span style="color: #008080;"> </span>$a<span style="color: #800080;">[</span>$i<span style="color: #800080;"> 1]= </span>mt_rand<span style="color: #008080;">(</span>$min<span style="color: #800080;">, </span>$max<span style="color: #800080;"></span>);<span style="color: #000000;"></span>162<span style="color: #008080;"> </span> }<span style="color: #000000;"></span>163<span style="color: #008080;"> </span>if<span style="color: #0000ff;">(</span>$c<span style="color: #800080;">==1</span>)<span style="color: #000000;"></span>164<span style="color: #008080;"> </span> {<span style="color: #000000;"></span>165<span style="color: #008080;"> </span>$ a<span style="color: #800080;"> [</span>$i<span style="color: #800080;">]=' - '</span>;<span style="color: #000000;"></span>166<span style="color: #008080;"> </span>$a<span style="color: #800080;">[</span>$i<span style="color: #800080;"> 1 ]= </span>mt_rand<span style="color: #008080;">(</span>$min<span style="color: #800080;">, </span>$max<span style="color: #800080;"></span>);<span style="color: #000000;"></span>167<span style="color: #008080;"> </span> }<span style="color: #000000;"></span>168<span style="color: #008080;"> </span>if<span style="color: #0000ff;">(</span>$c<span style="color: #800080;">==2</span>)<span style="color: #000000;"></span>169<span style="color: #008080;"> </span> {<span style="color: #000000;"></span>170 <span style="color: #008080;"> </span>$a<span style="color: #800080;">[</span>$i<span style="color: #800080;">]=' x '</span>;<span style="color: #000000;"></span>171<span style="color: #008080;"> </span>$a<span style="color: #800080;">[</span>$i<span style="color: #800080;"> 1]= </span>mt_rand<span style="color: #008080;">(</span>$min<span style="color: #800080;">, </span>$max<span style="color: #800080;"></span>);<span style="color: #000000;"></span>172<span style="color: #008080;"> </span> }<span style="color: #000000;"></span>173<span style="color: #008080;"> </span> }</span><span style="color: #008080;">174</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 計算での乗算を配列 $amd に格納します </span><span style="color: #008000;">*/</span><span style="color: #008080;"> 175</span> <span style="color: #800080;">$i</span>=0<span style="color: #000000;">;</span><span style="color: #008080;">176</span> <span style="color: #800080;">$j</span>=0<span style="color: #000000;">;</span><span style="color: #008080;">177</span> <span style="color: #0000ff;">while</span>(<span style="color: #800080;">$i</span><(2*<span style="color: #800080;">$num1</span>-1)) <span style="color: #008000;">//</span><span style="color: #008000;"> 演算子の左右にスペースを入れるかどうか上記の for ループと一致するようにしてください </span><span style="color: #008080;">178</span> <span style="color: #000000;"> {</span><span style="color: #008080;">179</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$a</span> [<span style="color: #800080;">$i</span>]==' x '<span style="color: #000000;">)</span><span style="color: #008080;">180</span> <span style="color: #000000;"> {</span><span style="color: #008080;">181</span> <span style="color: #800080;">$amd</span>[<span style="color: #800080;">$j</span>-1]=<span style="color: #800080;">$amd</span>[<span style="color: #800080;">$j</span>-1]*<span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span> 1 <span style="color: #000000;">];</span><span style="color: #008080;">182</span> <span style="color: #800080;">$i</span>=<span style="color: #800080;">$i</span> 2<span style="color: #000000;">;</span><span style="color: #008080;">183</span> <span style="color: #000000;"> }</span><span style="color: #008080;">184</span> <span style="color: #0000ff;">else</span><span style="color: #008080;">185</span> <span style="color: #000000;"> {</span><span style="color: #008080;">186</span> <span style="color: #800080;">$amd</span> [<span style="color: #800080;">$j</span>]=<span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span><span style="color: #000000;">];</span><span style="color: #008080;">187</span> <span style="color: #800080;">$j</span> <span style="color: #000000;">;</span><span style="color: #008080;">188</span> <span style="color: #800080;">$i</span> <span style="color: #000000;">;</span><span style="color: #008080;">189</span> <span style="color: #000000;"> }</span><span style="color: #008080;">190</span> <span style="color: #000000;"> }</span><span style="color: #008080;">191</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 方程式 $re の答えを計算します </span><span style="color: #008000;">*/</span><span style="color: #008080;">192</span> <span style="color: #800080;">$re</span>=<span style="color: #800080;">$amd</span>[0<span style="color: #000000;">];</span><span style="color: #008080;">193</span> <span style="color: #800080;">$k</span>=1<span style="color: #000000;">;</span> <span style="color: #008080;">194</span> <span style="color: #0000ff;">while</span>(<span style="color: #800080;">$k</span><<span style="color: #800080;">$j</span>) <span style="color: #008000;">//</span><span style="color: #008000;"> オペレーターが左か右かスペースは、上記の for ループ </span><span style="color: #008080;">195</span> <span style="color: #000000;"> {</span><span style="color: #008080;">196</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$amd</span>) と一致している必要があります。 [<span style="color: #800080;">$k</span>]==' '<span style="color: #000000;">)</span><span style="color: #008080;">197</span> <span style="color: #000000;"> {</span><span style="color: #008080;">198</span> <span style="color: #800080;">$re</span> =<span style="color: #800080;">$re</span> <span style="color: #800080;">$amd</span>[<span style="color: #800080;">$k</span> 1<span style="color: #000000;">];</span><span style="color: #008080;">199</span> <span style="color: #800080;">$k</span> =<span style="color: #800080;">$k</span> 2<span style="color: #000000;">;</span><span style="color: #008080;">200</span> <span style="color: #0000ff;">続行</span><span style="color: #000000;">;</span><span style="color: #008080;">201</span> <span style="color: #000000;"> }</span><span style="color: #008080;">202</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$amd</span>[<span style="color: #800080;">$k</span>]==' - '<span style="color: #000000;">)</span><span style="color: #008080;">203</span> <span style="color: #000000;"> {</span><span style="color: #008080;">204</span> <span style="color: #800080;">$re</span>=<span style="color: #800080;">$re</span>-<span style="color: #800080;">$amd</span>[<span style="color: #800080;">$ k</span> 1<span style="color: #000000;">];</span><span style="color: #008080;">205</span> <span style="color: #800080;">$k</span>=<span style="color: #800080;">$k</span> 2<span style="color: #000000;">;</span><span style="color: #008080;">206</span> <span style="color: #000000;"> }</span><span style="color: #008080;">207</span> <span style="color: #000000;"> }</span><span style="color: #008080;">208</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 配列内の値を連結します文字列 計算式 $str </span><span style="color: #008000;">*/</span><span style="color: #008080;">209</span> <span style="color: #800080;">$str</span>=<span style="color: #800080;">$a</span>[0<span style="color: #000000;">];</span><span style="color: #008080;">210</span> <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=1;<span style="color: #800080;">$i</span><(2*<span style="color: #800080;">$num1</span>-1 );<span style="color: #800080;">$i</span> <span style="color: #000000;">)</span><span style="color: #008080;">211</span> <span style="color: #000000;"> {</span><span style="color: #008080;">212</span> <span style="color: #800080;">$str</span>.=<span style="color: #800080;">$a </span>[<span style="color: #800080;">$i</span><span style="color: #000000;">];</span><span style="color: #008080;">213</span> <span style="color: #000000;"> }</span><span style="color: #008080;">214</span> <span style="color: #800080;">$result</span>- >r1=<span style="color: #800080;">$re</span><span style="color: #000000;">;</span><span style="color: #008080;">215</span> <span style="color: #800080;">$str</span>=<span style="color: #800080;">$str</span>。" = " <span style="color: #000000;"> ;</span><span style="color: #008080;">216</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$str</span><span style="color: #000000;">;</span><span style="color: #008080;">217</span> <span style="color: #000000;"> }</span><span style="color: #008080;">218</span> <span style="color: #008080;">219</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 演算子は加算、減算、除算のメソッドです </span><span style="color: #008000;">*/</span><span style="color: #008080;"> 220</span> <span style="color: #0000ff;">function</span> addSubDiv(<span style="color: #800080;">$min</span>,<span style="color: #800080;">$max</span>,<span style="color: #800080;">$num1</span>,<span style="color: #800080;">$result</span><span style="color: #000000;">)</span><span style="color: #008080;">221</span> <span style="color: #000000;"> {</span><span style="color: #008080;">222</span> <span style="color: #800080;">$a</span>[0]= <span style="color: #008080;">mt_rand</span>(<span style="color: #800080;"> $ min</span>, <span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;">223</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 計算内の数値と演算子を配列 $a </span><span style="color: #008000;">*/</span><span style="color: #008080;">224</span> <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=1;<span style="color: #800080;">$i</span>< ( 2*<span style="color: #800080;">$num1</span>-1);<span style="color: #800080;">$i</span>=<span style="color: #800080;">$i</span> 2<span style="color: #000000;">) </span><span style="color: #008080;">225</span> <span style="color: #000000;"> { </span><span style="color: #008080;">226</span> <span style="color: #800080;">$c</span>= <span style="color: #008080;">mt_rand</span>(0, 2<span style="color: #000000;">);</span><span style="color: #008080;">227</span> <span style="color: #0000ff;">if </span>(<span style="color: #800080;">$c</span>==0<span style="color: #000000;">)</span><span style="color: #008080;">228</span> <span style="color: #000000;"> {</span><span style="color: #008080;">229</span> <span style="color: #800080;">$a</span> [<span style="color: #800080;">$i</span>]=' '<span style="color: #000000;">;</span><span style="color: #008080;">230</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span> 1]= <span style="color: #008080;"> mt_rand</span>(<span style="color: #800080;">$min</span>, <span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;">231</span> <span style="color: #000000;"> }</span><span style="color: #008080;">232</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$c</span>==1<span style="color: #000000;">)</span><span style="color: #008080;">233</span> <span style="color: #000000;"> {</span><span style="color: #008080;">234</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span>]=' - '<span style="color: #000000;">;</span><span style="color: #008080;">235</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span> 1]= <span style="color: #008080;">mt_rand</span>(<span style="color: #800080;">$min</span>, <span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;">236</span> <span style="color: #000000;"> }</span><span style="color: #008080;">237</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$c</span>==2<span style="color: #000000;">)</span><span style="color: #008080;">238</span> <span style="color: #000000;"> {</span><span style="color: #008080;">239</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span>]=' ÷ '<span style="color: #000000;">;</span><span style="color: #008080;">240</span> <span style="color: #800080;">$a</span> [ <span style="color: #800080;">$i</span> 1]= <span style="color: #008080;">mt_rand</span>(<span style="color: #800080;">$min</span>, <span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;">241</span> <span style="color: #000000;"> }</span><span style="color: #008080;">242</span> <span style="color: #000000;"> }</span><span style="color: #008080;">243</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 計算式の除算後の計算を配列 $amd に格納 </span><span style="color: #008000;">*/</span><span style="color: #008080;"> 244</span> <span style="color: #800080;">$i</span>=0<span style="color: #000000;">;</span><span style="color: #008080;">245</span> <span style="color: #800080;">$j</span>=0<span style="color: #000000;">;</span><span style="color: #008080;">246</span> <span style="color: #0000ff;">while</span>(<span style="color: #800080;">$i</span><(2*<span style="color: #800080;">$num1</span>-1<span style="color: #000000;">))</span><span style="color: #008080;">247</span> <span style="color: #000000;"> { </span><span style="color: #008080;">248</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span>]==' ÷ '<span style="color: #000000;">)</span> <span style="color: #008080;">249</span> <span style="color: #000000;"> {</span><span style="color: #008080;">250</span> <span style="color: #0000ff;">while</span>((<span style="color: #800080;">$amd</span>[<span style="color: #800080;">$j</span>-1] % <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span> 1]!=0) || <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span> 1]==0 ) <span style="color: #008000;"> //</span><span style="color: #008000;">剰余による除算を避ける</span><span style="color: #008080;">251</span> <span style="color: #000000;"> {</span><span style="color: #008080;">252</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;"> $i </span> 1]= <span style="color: #008080;">mt_rand</span>(<span style="color: #800080;">$min</span>,<span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;">253</span> <span style="color: #000000;"> } </span><span style="color: #008080;">254</span> <span style="color: #800080;">$amd</span>[<span style="color: #800080;">$j</span>-1]=<span style="color: #800080;">$amd</span>[<span style="color: #800080;">$j</span> -1 ]/<span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span> 1<span style="color: #000000;">];</span><span style="color: #008080;">255</span> <span style="color: #800080;">$i</span>=<span style="color: #800080;">$ i</span> 2<span style="color: #000000;">;</span><span style="color: #008080;">256</span> <span style="color: #000000;"> }</span><span style="color: #008080;">257</span> <span style="color: #0000ff;">else</span><span style="color: #008080;">258</span> <span style="color: #000000;"> {</span><span style="color: #008080;">259</span> <span style="color: #800080;">$amd</span>[<span style="color: #800080;">$j</span>]=<span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span><span style="color: #000000;"> ]; </span><span style="color: #008080;">260</span> <span style="color: #800080;">$j</span> <span style="color: #000000;">;</span><span style="color: #008080;">261</span> <span style="color: #800080;">$i</span> <span style="color: #000000;">;</span><span style="color: #008080;"> 262</span> <span style="color: #000000;"> }</span><span style="color: #008080;">263</span> <span style="color: #000000;"> }</span><span style="color: #008080;">264</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 方程式 $re の答えを計算します </span><span style="color: #008000;">*/</span><span style="color: #008080;">265</span> <span style="color: #800080;"> $re </span>=<span style="color: #800080;">$amd</span>[0<span style="color: #000000;">];</span><span style="color: #008080;">266</span> <span style="color: #800080;">$k</span>=1<span style="color: #000000;">;</span><span style="color: #008080;">267 </span> <span style="color: #0000ff;">その間</span>(<span style="color: #800080;">$k</span><<span style="color: #800080;">$j</span><span style="color: #000000;">)</span><span style="color: #008080;">268</span> <span style="color: #000000;"> {</span> <span style="color: #008080;">269</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$amd</span>[<span style="color: #800080;">$k</span>]==' '<span style="color: #000000;">)</span><span style="color: #008080;">270 </span> <span style="color: #000000;"> {</span><span style="color: #008080;">271</span> <span style="color: #800080;">$re</span>=<span style="color: #800080;">$re</span> <span style="color: #800080;">$amd</span>[<span style="color: #800080;">$k</span> 1 <span style="color: #000000;">];</span><span style="color: #008080;">272</span> <span style="color: #800080;">$k</span>=<span style="color: #800080;">$k</span> 2<span style="color: #000000;">;</span><span style="color: #008080;">273</span> <span style="color: #0000ff;"> continue</span><span style="color: #000000;">;</span><span style="color: #008080;">274</span> <span style="color: #000000;"> }</span><span style="color: #008080;">275</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$amd</span> [<span style="color: #800080;">$k</span>]==' - '<span style="color: #000000;">)</span><span style="color: #008080;">276</span> <span style="color: #000000;"> {</span><span style="color: #008080;">277</span> <span style="color: #800080;">$re</span>= <span style="color: #800080;">$re</span>-<span style="color: #800080;">$amd</span>[<span style="color: #800080;">$k</span> 1<span style="color: #000000;">];</span><span style="color: #008080;">278</span> <span style="color: #800080;">$k</span> =<span style="color: #800080;">$k</span> 2<span style="color: #000000;">;</span><span style="color: #008080;">279</span> <span style="color: #000000;"> }</span><span style="color: #008080;">280</span> <span style="color: #000000;"> }</span><span style="color: #008080;"> 281</span> <span style="color: #008080;">282</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 計算を文字列 $str </span><span style="color: #008000;">*/</span><span style="color: #008080;">283</span> <span style="color: #800080;">$ str</span>=<span style="color: #800080;">$a</span>[0<span style="color: #000000;">];</span><span style="color: #008080;">284</span> <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=1 ;<span style="color: #800080;">$i</span><(2*<span style="color: #800080;">$num1</span>-1);<span style="color: #800080;">$i</span> <span style="color: #000000;">)</span><span style="color: #008080;">285</span> <span style="color: #000000;"> { </span><span style="color: #008080;">286</span> <span style="color: #800080;">$str</span>.=<span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span><span style="color: #000000;">];</span><span style="color: #008080;"> 287</span> <span style="color: #000000;"> }</span><span style="color: #008080;">288</span> <span style="color: #800080;">$result</span>->r1=<span style="color: #800080;">$re</span><span style="color: #000000;">;</span><span style="color: #008080;">289 </span> <span style="color: #800080;">$str</span>=<span style="color: #800080;">$str</span>." = "<span style="color: #000000;">;</span><span style="color: #008080;">290</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$str </span><span style="color: #000000;">;</span><span style="color: #008080;">291</span> <span style="color: #000000;"> }</span><span style="color: #008080;">292</span> <span style="color: #008080;">293</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 演算子は加算、減算、乗算、除算のメソッドです </span><span style="color: #008000;">*/</span> <span style="color: #008080;"> 294</span> <span style="color: #0000ff;">function</span> addSubMulDiv(<span style="color: #800080;">$min</span>,<span style="color: #800080;">$max</span>,<span style="color: #800080;">$num1</span>,<span style="color: #800080;">$result</span><span style="color: #000000;">)</span><span style="color: #008080;">295</span> <span style="color: #000000;"> {</span><span style="color: #008080;">296</span> <span style="color: #800080;">$a</span>[0]= <span style="color: #008080;">mt_rand</span>(<span style="color: #800080;">$ min</span>, <span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;">297</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 計算に数値と演算子を保存します配列 $a </span><span style="color: #008000;">*/</span><span style="color: #008080;">298</span> <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=1;<span style="color: #800080;">$i</span>) <( 2*<span style="color: #800080;">$num1</span>-1);<span style="color: #800080;">$i</span>=<span style="color: #800080;">$i</span> 2<span style="color: #000000;">)</span><span style="color: #008080;">299</span> <span style="color: #000000;"> { </span><span style="color: #008080;">300</span> <span style="color: #800080;">$c</span>= <span style="color: #008080;">mt_rand</span>(0, 3<span style="color: #000000;">);</span><span style="color: #008080;">301</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$c</span>==0<span style="color: #000000;">)</span><span style="color: #008080;">302</span> <span style="color: #000000;"> {</span><span style="color: #008080;">303</span> <span style="color: #800080;">$a </span> [<span style="color: #800080;">$i</span>]=' '<span style="color: #000000;">;</span><span style="color: #008080;">304</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span> 1]= <span style="color: #008080;"> mt_rand</span>(<span style="color: #800080;">$min</span>, <span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;">305</span> <span style="color: #000000;"> }</span><span style="color: #008080;"> 306</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$c</span>==1<span style="color: #000000;">)</span><span style="color: #008080;">307</span> <span style="color: #000000;"> {</span><span style="color: #008080;">308</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span>]=' - '<span style="color: #000000;">;</span><span style="color: #008080;">309</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;">$ i</span> 1]= <span style="color: #008080;">mt_rand</span>(<span style="color: #800080;">$min</span>, <span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;">310</span> <span style="color: #000000;"> }</span><span style="color: #008080;">311</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$c</span>==2<span style="color: #000000;">)</span><span style="color: #008080;">312</span> <span style="color: #000000;"> {</span><span style="color: #008080;">313</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span>]=' x '<span style="color: #000000;">;</span><span style="color: #008080;">314</span> <span style="color: #800080;">$a</span>[ <span style="color: #800080;">$i</span> 1]= <span style="color: #008080;">mt_rand</span>(<span style="color: #800080;">$min</span>, <span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;"> 315</span> <span style="color: #000000;"> }</span><span style="color: #008080;">316</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$c</span>==3<span style="color: #000000;">)</span><span style="color: #008080;">317</span> <span style="color: #000000;"> {</span> <span style="color: #008080;">318</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span>]=' ÷ '<span style="color: #000000;">;</span><span style="color: #008080;">319</span> <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span> 1]= <span style="color: #008080;">mt_rand</span>(<span style="color: #800080;">$min</span>, <span style="color: #800080;">$max</span><span style="color: #000000;">);</span><span style="color: #008080;">320 </span> <span style="color: #000000;"> }</span><span style="color: #008080;">321</span> <span style="color: #000000;"> }</span><span style="color: #008080;">322</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 式の割り算が完了すると、計算式は配列 $amd </span><span style="color: #008000;">*/</span><span style="color: #008080;">323</span> <span style="color: #800080;">$i</span>=0<span style="color: #000000;">;</span><span style="color: #008080;">324 </span>$j<span style="color: #800080;">=0</span>;<span style="color: #000000;"></span>325<span style="color: #008080;"> </span>while<span style="color: #0000ff;">(</span>$i<span style="color: #800080;"><(2*</span>$ num1<span style="color: #800080;">-1</span>))<span style="color: #000000;"></span>326<span style="color: #008080;"> </span> {<span style="color: #000000;"></span>327<span style="color: #008080;"> </span>if<span style="color: #0000ff;">(</span>$a[ <span style="color: #800080;">$i</span>]==' x '<span style="color: #800080;">)</span><span style="color: #000000;">328</span> <span style="color: #008080;"> {</span><span style="color: #000000;">329</span> <span style="color: #008080;">$amd</span> [<span style="color: #800080;">$j</span>-1]=<span style="color: #800080;">$amd</span>[<span style="color: #800080;">$j</span>-1]*<span style="color: #800080;">$a</span>[<span style="color: #800080;">$i </span> 1<span style="color: #800080;">];</span><span style="color: #000000;">330</span> <span style="color: #008080;">$i</span>=<span style="color: #800080;">$i</span> 2<span style="color: #800080;">;</span><span style="color: #000000;">331</span> <span style="color: #008080;"> }</span><span style="color: #000000;">332</span> <span style="color: #008080;">else</span> <span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">$a</span>[<span style="color: #800080;">$i</span>]== ' ÷ '<span style="color: #800080;">)</span><span style="color: #000000;">333</span> <span style="color: #008080;"> {</span><span style="color: #000000;">334</span> <span style="color: #008080;">while</span>((<span style="color: #0000ff;">$amd</span>[<span style="color: #800080;"> $j</span>-1] % <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span> 1]!=0) || <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i </span> 1]==0 ) <span style="color: #800080;">//</span><span style="color: #008000;">剰余による除算を避ける</span><span style="color: #008000;">335</span> <span style="color: #008080;"> {</span><span style="color: #000000;">336</span> <span style="color: #008080;">$ a</span>[<span style="color: #800080;">$i</span> 1]= <span style="color: #800080;">mt_rand</span>(<span style="color: #008080;">$min</span>,<span style="color: #800080;">$max</span><span style="color: #800080;">);</span><span style="color: #000000;">337</span> <span style="color: #008080;"> }</span><span style="color: #000000;">338</span> <span style="color: #008080;">$amd</span>[<span style="color: #800080;">$j</span>-1]=<span style="color: #800080;">$amd</span>[ <span style="color: #800080;">$j</span>-1]/<span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span> 1<span style="color: #800080;">];</span><span style="color: #000000;">339</span> <span style="color: #008080;"> $i </span>=<span style="color: #800080;">$i</span> 2<span style="color: #800080;">;</span><span style="color: #000000;">340</span> <span style="color: #008080;"> }</span><span style="color: #008080;">341</span> <span style="color: #0000ff;">else</span><span style="color: #008080;">342</span> <span style="color: #000000;"> {</span><span style="color: #008080;">343</span> <span style="color: #800080;">$amd</span>[<span style="color: #800080;"> $j</span>]=<span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span><span style="color: #000000;">];</span><span style="color: #008080;">344</span> <span style="color: #800080;">$j</span> <span style="color: #000000;"> ;</span><span style="color: #008080;">345</span> <span style="color: #800080;">$i</span> <span style="color: #000000;">;</span><span style="color: #008080;">346</span> <span style="color: #000000;"> }</span><span style="color: #008080;">347</span> <span style="color: #000000;"> }</span><span style="color: #008080;">348</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 方程式 $re の答えを計算します </span><span style="color: #008000;">*/</span><span style="color: #008080;">349</span> <span style="color: #800080;">$ re</span>=<span style="color: #800080;">$amd</span>[0<span style="color: #000000;">];</span><span style="color: #008080;">350</span> <span style="color: #800080;">$k</span>=1<span style="color: #000000;">;</span><span style="color: #008080;"> 351</span> <span style="color: #0000ff;">ながら</span>(<span style="color: #800080;">$k</span><<span style="color: #800080;">$j</span><span style="color: #000000;">)</span><span style="color: #008080;">352</span> <span style="color: #000000;"> { </span><span style="color: #008080;">353</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$amd</span>[<span style="color: #800080;">$k</span>]==' '<span style="color: #000000;">)</span><span style="color: #008080;"> 354</span> <span style="color: #000000;"> {</span><span style="color: #008080;">355</span> <span style="color: #800080;">$re</span>=<span style="color: #800080;">$re</span> <span style="color: #800080;">$amd</span>[<span style="color: #800080;">$k</span> 1<span style="color: #000000;">];</span><span style="color: #008080;">356</span> <span style="color: #800080;">$k</span>=<span style="color: #800080;">$k</span> 2<span style="color: #000000;">;</span><span style="color: #008080;">357</span> <span style="color: #0000ff;">続行</span><span style="color: #000000;">;</span><span style="color: #008080;">358</span> <span style="color: #000000;"> }</span><span style="color: #008080;">359</span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$amd[ </span>$k<span style="color: #800080;">]==' - '</span>)<span style="color: #000000;"></span>360<span style="color: #008080;"> </span> {<span style="color: #000000;"></span>361<span style="color: #008080;"> </span>$re<span style="color: #800080;"> =</span>$re<span style="color: #800080;">-</span>$amd<span style="color: #800080;">[</span>$k<span style="color: #800080;"> 1</span>];<span style="color: #000000;"></span>362<span style="color: #008080;"> </span>$k <span style="color: #800080;">=</span>$k<span style="color: #800080;"> 2</span>;<span style="color: #000000;"></span>363<span style="color: #008080;"> </span> }<span style="color: #000000;"></span>364<span style="color: #008080;"> </span> }<span style="color: #000000;"></span>365 <span style="color: #008080;"> </span>/*<span style="color: #008000;"></span> 計算を文字列 $str <span style="color: #008000;"></span>*/<span style="color: #008000;"></span>366<span style="color: #008080;"> </span>$str<span style="color: #800080;"> に入れます=</span>$a<span style="color: #800080;">[0</span>];<span style="color: #000000;"></span>367<span style="color: #008080;"> </span>for<span style="color: #0000ff;">(</span>$i<span style="color: #800080;">=1;</span>$i <span style="color: #800080;"><(2*</span>$num1<span style="color: #800080;">-1);</span>$i<span style="color: #800080;"> </span>)<span style="color: #000000;"></span>368<span style="color: #008080;"> </span> {<span style="color: #000000;"></span> 369<span style="color: #008080;"> </span>$str<span style="color: #800080;">.=</span>$a<span style="color: #800080;">[</span>$i<span style="color: #800080;"></span>];<span style="color: #000000;"></span>370<span style="color: #008080;"> </span> }<span style="color: #008080;">371</span> <span style="color: #800080;">$result</span>->r1=<span style="color: #800080;">$re</span><span style="color: #000000;">;</span><span style="color: #008080;">372</span> <span style="color: #800080;">$str </span>=<span style="color: #800080;">$str</span>." = "<span style="color: #000000;">;</span><span style="color: #008080;">373</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$str</span><span style="color: #000000;">;</span><span style="color: #008080;">374</span> <span style="color: #000000;"> }</span><span style="color: #008080;">375</span> <span style="color: #008080;">376</span> <span style="color: #800080;">$r</span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> 結果();</span><span style="color: #008080;">377</span> <span style="color: #008080;">378</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> 2 つの数値の加算と減算</span><span style="color: #008000;">*/</span><span style="color: #008080;">379</span> <span style="color: #0000ff;">if</span>((<span style="color: #800080;">$num1</span>==2) && (<span style="color: #800080;">$mul</span>=='f') && (<span style="color: #800080;">$div </span>=='f'<span style="color: #000000;">))</span><span style="color: #008080;">380</span> <span style="color: #000000;"> {</span><span style="color: #008080;">381</span> <span style="color: #800080;">$question</span> = <span style="color: #008080;">fopen </span>("question.txt", "w"<span style="color: #000000;">);</span><span style="color: #008080;">382</span> <span style="color: #800080;">$answer</span>= <span style="color: #008080;">fopen</span>("answer.txt" , "w"<span style="color: #000000;">);</span><span style="color: #008080;">383</span> <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=0;<span style="color: #800080;">$i</span><<span style="color: #800080;"> $num</span>;<span style="color: #800080;">$i</span> <span style="color: #000000;">)</span><span style="color: #008080;">384</span> <span style="color: #000000;"> {</span><span style="color: #008080;">385</span> <span style="color: #800080;">$j</span> =0<span style="color: #000000;">;</span><span style="color: #008080;">386</span> <span style="color: #800080;">$bool</span>=<span style="color: #0000ff;">true</span><span style="color: #000000;">;</span><span style="color: #008080;">387</span> <span style="color: #800080;"> $ b</span>[<span style="color: #800080;">$i</span>]= addSub(<span style="color: #800080;">$min</span>, <span style="color: #800080;">$max</span>, <span style="color: #800080;">$num1</span>, <span style="color: #800080;">$r </span><span style="color: #000000;">);</span><span style="color: #008080;">388</span> <span style="color: #0000ff;">while</span>((<span style="color: #800080;">$r</span>->r1)//<span style="color: #008000;">結果が負の場合、再ランダム</span><span style="color: #008080;">389</span> <span style="color: #000000;"> {</span><span style="color: #008080;">390</span> <span style="color: #800080;">$b</span>[<span style="color: #800080;">$ i</span>]= addSub(<span style="color: #800080;">$min</span>, <span style="color: #800080;">$max</span>, <span style="color: #800080;">$num1</span>, <span style="color: #800080;">$r</span><span style="color: #000000;">);</span><span style="color: #008080;">391</span> <span style="color: #000000;"> }</span>
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。