1.首先,暴力程序 baoli.cpp
2.然后,优化程序 hao.cpp
#include
<iostream>
using
namespace
std
;
int
main
(
)
{
int
a
,
b
;
cin
>>
a
>>
b
;
cout
<<
a
+
b
;
return
0
;
}
#include
<iostream>
using
namespace
std
;
int
main
(
)
{
int
a
,
b
;
cin
>>
a
>>
b
;
while
(
a
--
)
b
++
;
cout
<<
b
;
return
0
;
}
3.然后,随机数生成程序 rand.cpp
4.<1>若为Windows,创建txt文件,写入如下命令
改后缀为.bat,运行批处理文件。若正确,则会提示;若不对,则也会提示并指出错误数据。
4.<2>若为Linux,创建空文本,写入如下命令,注意关键地方必须有分隔符。
然后保存为test.sh,然后打开终端,输入 chmod +x test.sh 释放执行权限,最后用 ./test.sh 来执行它。若正确,则会持续执行;若不对,则会提示错误数据行数及内容。
PS:注意一定要写 ./ 表示执行的文件在当前目录下。还有,若对拍系列文件不在根目录,先用 cd 命令到达所在目录再执行其他命令。
#include
<iostream>
#include
<cstdlib>
#include
<ctime>
using
namespace
std
;
int
main
(
)
{
srand
(
time
(
NULL
))
;
int
a
=
(
double
)
rand
(
)/
RAND_MAX
*
30000
;
int
b
=
(
double
)
rand
(
)/
RAND_MAX
*
30000
;
cout
<<
a
<<
" "
<<
b
<<
endl
;
return
0
;
}
改后缀为.bat,运行批处理文件。若正确,则会提示;若不对,则也会提示并指出错误数据。
@echo
off
:
loop
rand
.
exe
>
date
.
in
hao
.
exe
<
date
.
in
>
hao
.
out
baoli
.
exe
<
date
.
in
>
baoli
.
out
fc
hao
.
out
baoli
.
out
if
not
errorlevel
1
goto
loop
pause
goto
loop
然后保存为test.sh,然后打开终端,输入 chmod +x test.sh 释放执行权限,最后用 ./test.sh 来执行它。若正确,则会持续执行;若不对,则会提示错误数据行数及内容。
PS:注意一定要写 ./ 表示执行的文件在当前目录下。还有,若对拍系列文件不在根目录,先用 cd 命令到达所在目录再执行其他命令。
#!/bin/bash
while
true
;
do
.
/
rand
>
input
.
/
baoli
<
input
>
baoli
.
out
.
/
hao
<
input
>
hao
.
out
diff
baoli
.
out
hao
.
out
if
[
$?
-
ne
0
]
;
then
break
;
fi
done