Home > Backend Development > PHP Tutorial > 软件工程结对功课02

软件工程结对功课02

WBOY
Release: 2016-06-13 12:29:13
Original
1115 people have browsed it

软件工程结对作业02

1.设计思想:

  本次任务我用php实现的主要功能,默认必须有加减法。

  首先,创建index.php文件,在HTML语句里创建表单,表单内容包括,出题数目,最大最小值,及其他的一些选项。

  然后,创建rubric.php文件,将表单信息提交到此文件下,四则运算方法实现时调用传递过来的值。实现四则运算的方法和前几次用Java时的方法差不多,将代码做了修改和优化。将题目和答案分别放入question.txtanswer.txt文件里,以备后用。

  第三,创建submitAnswer.phpacceptAnswer.phpdeleteAnswer.phpjudgeAnswer.php文件,分别用于在线提交答案,接收答案,删除答案和判断答案。提交的答案放在answer1.txt文件里,判断答案时通过比较answer.txtanswer1.txt文件里的内容即可。

2.源程序代码

 

<span style="color: #008080;">  1</span> index.<span style="color: #000000;">php</span><span style="color: #008080;">  2</span> <span style="color: #008080;">  3</span> <!--<span style="color: #008080;">  4</span> start <span style="color: #008080;">date</span> 2016/3/28<span style="color: #008080;">  5</span> completion <span style="color: #008080;">date</span> 2016/4/7<span style="color: #008080;">  6</span> <span style="color: #000000;">author Jing</span><span style="color: #008080;">  7</span> <span style="color: #000000;">this program is about four arithmetic operation</span><span style="color: #008080;">  8</span> --><span style="color: #008080;">  9</span> <span style="color: #008080;"> 10</span>     <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 style="color: #0000ff;">function<span style="color: #000000;"> check() {<span style="color: #008080;"> 15                 <span style="color: #0000ff;">var tt=/^(0|[1-9]\d*)$/<span style="color: #000000;">;<span style="color: #008080;"> 16                 <span style="color: #0000ff;">if(!tt.test(form1.<span style="color: #008080;">min.<span style="color: #000000;">value))<span style="color: #008080;"> 17 <span style="color: #000000;">                {<span style="color: #008080;"> 18                     alert('最小值输入不合法'<span style="color: #000000;">);<span style="color: #008080;"> 19                     form1.<span style="color: #008080;">min.<span style="color: #000000;">focus();<span style="color: #008080;"> 20                     <span style="color: #0000ff;">return <span style="color: #0000ff;">false<span style="color: #000000;">;<span style="color: #008080;"> 21 <span style="color: #000000;">                }<span style="color: #008080;"> 22                 <span style="color: #0000ff;">if(!tt.test(form1.<span style="color: #008080;">max.value) || (form1.<span style="color: #008080;">max.value<form1.<span style="color: #008080;">min.<span style="color: #000000;">value))<span style="color: #008080;"> 23 <span style="color: #000000;">                {<span style="color: #008080;"> 24                     alert('最大值输入不合法'<span style="color: #000000;">);<span style="color: #008080;"> 25                     form1.<span style="color: #008080;">min.<span style="color: #000000;">focus();<span style="color: #008080;"> 26                     <span style="color: #0000ff;">return <span style="color: #0000ff;">false<span style="color: #000000;">;<span style="color: #008080;"> 27 <span style="color: #000000;">                }<span style="color: #008080;"> 28                 <span style="color: #0000ff;">if(!tt.test(form1.num.value) || (form1.num.value==0<span style="color: #000000;">))<span style="color: #008080;"> 29 <span style="color: #000000;">                {<span style="color: #008080;"> 30                     alert('出题数目输入不合法'<span style="color: #000000;">);<span style="color: #008080;"> 31                     form1.num.<span style="color: #000000;">focus();<span style="color: #008080;"> 32                     <span style="color: #0000ff;">return <span style="color: #0000ff;">false<span style="color: #000000;">;<span style="color: #008080;"> 33 <span style="color: #000000;">                }<span style="color: #008080;"> 34         <span style="color: #0000ff;">return <span style="color: #0000ff;">true<span style="color: #000000;">;<span style="color: #008080;"> 35 <span style="color: #000000;">            }<span style="color: #008080;"> 36         </script><span style="color: #008080;"> 37</span>     <span style="color: #008080;"> 38</span>     <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="楷体">欢迎来到小学四则运算出题系统</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">默认只有两个数参与运算的加减法</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><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>         <input type="text" name="num"> <br><br><span style="color: #008080;"> 55</span>         <span style="color: #008080;"> 56</span>         <font color="blue" size="4">选择参与运算的数的个数</font><span style="color: #008080;"> 57</span>         <input type="radio" value="2" name="num1" checked>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><br><!--num1中的1位1 2 3的1,不是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" checked>否 <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" checked>否 <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="重置" name="send"><span style="color: #008080;"> 71</span>         </form>
<span style="color: #008080;"> 72</span>         </center><span style="color: #008080;"> 73</span>     <span style="color: #008080;"> 74</span> <span style="color: #008080;"> 75</span> <span style="color: #008080;"> 76</span> rubric.<span style="color: #000000;">php</span><span style="color: #008080;"> 77</span> <span style="color: #008080;"> 78</span> <span style="color: #008080;"> 79</span>     <span style="color: #008080;"> 80</span>         <meta charset="UTF-8"><span style="color: #008080;"> 81</span>         <title>出题界面</title><span style="color: #008080;"> 82</span>     <span style="color: #008080;"> 83</span>     <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>["min"];  <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><span style="color: #008000;">参与运算的个数</span><span style="color: #008080;">101</span> <span style="color: #000000;">            }</span><span style="color: #008080;">102</span>             <span style="color: #0000ff;">if</span>(<span style="color: #008080;">is_string</span>(<span style="color: #800080;">$_POST</span>["mul"<span style="color: #000000;">]))</span><span style="color: #008080;">103</span> <span style="color: #000000;">            {</span><span style="color: #008080;">104</span>                 <span style="color: #800080;">$mul</span>=<span style="color: #800080;">$_POST</span>["mul"];  <span style="color: #008000;">//</span><span style="color: #008000;">选择是否加入乘法 是t否f</span><span style="color: #008080;">105</span> <span style="color: #000000;">            }</span><span style="color: #008080;">106</span>             <span style="color: #0000ff;">if</span>(<span style="color: #008080;">is_string</span>(<span style="color: #800080;">$_POST</span>["div"<span style="color: #000000;">]))</span><span style="color: #008080;">107</span> <span style="color: #000000;">            {</span><span style="color: #008080;">108</span>                 <span style="color: #800080;">$div</span>=<span style="color: #800080;">$_POST</span>["div"];  <span style="color: #008000;">//</span><span style="color: #008000;">选择是否加入除法 是t否f</span><span style="color: #008080;">109</span> <span style="color: #000000;">            }</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;">array</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;">array</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;"> Result 类用于封装结果 </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>$num1;<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;"> 将算式中的数和运算符存入数组$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>(<span style="color: #800080;">$i</span>=1;<span style="color: #800080;">$i</span>$num1-1);<span style="color: #800080;">$i</span>=<span style="color: #800080;">$i</span>+2)  <span style="color: #008000;">//</span><span style="color: #008000;">(2*$num1-1) 为算式中参与运算的数和运算符个数之和</span><span style="color: #008080;">156</span> <span style="color: #000000;">                {</span><span style="color: #008080;">157</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;">158</span>                     <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$c</span>==0<span style="color: #000000;">)</span><span style="color: #008080;">159</span> <span style="color: #000000;">            {</span><span style="color: #008080;">160</span>                         <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span>]=' + '<span style="color: #000000;">;</span><span style="color: #008080;">161</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;">162</span> <span style="color: #000000;">            }</span><span style="color: #008080;">163</span>                     <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$c</span>==1<span style="color: #000000;">)</span><span style="color: #008080;">164</span> <span style="color: #000000;">            {</span><span style="color: #008080;">165</span>                         <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span>]=' - '<span style="color: #000000;">;</span><span style="color: #008080;">166</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;">167</span> <span style="color: #000000;">            }</span><span style="color: #008080;">168</span>                     <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$c</span>==2<span style="color: #000000;">)</span><span style="color: #008080;">169</span> <span style="color: #000000;">            {</span><span style="color: #008080;">170</span>                         <span style="color: #800080;">$a</span>[<span style="color: #800080;">$i</span>]=' x '<span style="color: #000000;">;</span><span style="color: #008080;">171</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;">172</span> <span style="color: #000000;">            }</span><span style="color: #008080;">173</span> <span style="color: #000000;">                }</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>$num1-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>$j)  <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;">continue</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>$num1-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>$num1-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>$num1-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;">while</span>(<span style="color: #800080;">$k</span>$j<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>$num1-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>$num1-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>                 <span style="color: #800080;">$j</span>=0<span style="color: #000000;">;</span><span style="color: #008080;">325</span>                 <span style="color: #0000ff;">while</span>(<span style="color: #800080;">$i</span>$num1-1<span style="color: #000000;">))</span><span style="color: #008080;">326</span> <span style="color: #000000;">                {</span><span style="color: #008080;">327</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;">328</span> <span style="color: #000000;">                    {</span><span style="color: #008080;">329</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;">330</span>                         <span style="color: #800080;">$i</span>=<span style="color: #800080;">$i</span>+2<span style="color: #000000;">;</span><span style="color: #008080;">331</span> <span style="color: #000000;">                    }</span><span style="color: #008080;">332</span>                     <span style="color: #0000ff;">else</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;">333</span> <span style="color: #000000;">                    {</span><span style="color: #008080;">334</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;">335</span> <span style="color: #000000;">                        {</span><span style="color: #008080;">336</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;">337</span> <span style="color: #000000;">                        }</span><span style="color: #008080;">338</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;">339</span>                         <span style="color: #800080;">$i</span>=<span style="color: #800080;">$i</span>+2<span style="color: #000000;">;</span><span style="color: #008080;">340</span> <span style="color: #000000;">                    }</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;">while</span>(<span style="color: #800080;">$k</span>$j<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;">continue</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>[<span style="color: #800080;">$k</span>]==' - '<span style="color: #000000;">)</span><span style="color: #008080;">360</span> <span style="color: #000000;">                    {</span><span style="color: #008080;">361</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;">362</span>                         <span style="color: #800080;">$k</span>=<span style="color: #800080;">$k</span>+2<span style="color: #000000;">;</span><span style="color: #008080;">363</span> <span style="color: #000000;">                    }</span><span style="color: #008080;">364</span> <span style="color: #000000;">                }</span><span style="color: #008080;">365</span>                 <span style="color: #008000;">/*</span><span style="color: #008000;"> 将算式放入字符串$str </span><span style="color: #008000;">*/</span><span style="color: #008080;">366</span>                 <span style="color: #800080;">$str</span>=<span style="color: #800080;">$a</span>[0<span style="color: #000000;">];</span><span style="color: #008080;">367</span>                 <span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span>=1;<span style="color: #800080;">$i</span>$num1-1);<span style="color: #800080;">$i</span>++<span style="color: #000000;">)</span><span style="color: #008080;">368</span> <span style="color: #000000;">                {</span><span style="color: #008080;">369</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;">370</span> <span style="color: #000000;">                }</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;"> Result();</span><span style="color: #008080;">377</span>             <span style="color: #008080;">378</span>             <span style="color: #008000;">/*</span><span style="color: #008000;"> 两个数的加减法 </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>$num;<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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template