对拍方法 pascal 

这次noip看到旁边用c++那位对拍得好爽,

自己也搜了一下对拍的方法,

可惜多不适合pascal党,

所以我中和几种方法,终于弄出了一个用 命令提示符对拍的方法。

 

首先要有一个 百分百对的程序

我写了个排序

 

a.pas

var
 n,e:longint;
 a:array[0..1000]of longint;

procedure init;
var
 i:longint;
begin
 read(n);
 for i:=1 to n do read(a[i]);
end;

procedure main;
var
 i,j:longint;
begin
 for i:=1 to n-1 do
  for j:=i+1 to n do
   if a[i]>a[j] then
    begin
    a[0]:=a[i];
    a[i]:=a[j];
    a[j]:=a[0];
    end;
end;

procedure print;
var
 i:longint;
begin
 for i:=1 to n do write(a[i],' ');
end;

begin
 assign(input,'in.txt');
 assign(output,'o1.txt');
 reset(input);
 rewrite(output);
 init;
 main;
 print;
 close(input);
 close(output);
end.

还要有一个待检验的程序,快拍(经检验是正确的,呵呵)

b.pas

var
 n,e:longint;
 a:array[0..1000]of longint;

procedure init;
var
 i:longint;
begin
 read(n);
 for i:=1 to n do read(a[i]);
end;

procedure qsort(x,y:longint);
var
 i,j,k:longint;

begin
 if x>=y then exit;
 i:=x;
 j:=y;
 k:=a[(x+y)div 2];
 while i<=j do
  begin
   while a[i]<k do inc(i);
   while a[j]>k do dec(j);
   if i<=j then
    begin
     a[0]:=a[i];
     a[i]:=a[j];
     a[j]:=a[0];
     inc(i);
     dec(j);
    end;
  end;
  qsort(x,j);
  qsort(i,y);
end;


procedure print;
var
 i:longint;
begin
 for i:=1 to n do write(a[i],' ');
end;

begin
 assign(input,'in.txt');
 assign(output,'o2.txt');
 reset(input);
 rewrite(output);
 init;
 qsort(1,n);
 print;
 close(input);
 close(output);
end.

还要有一个 数据生成器

maker.pas


var
 n,i:longint;
begin
 assign(output,'in.txt');
 rewrite(output);
 randomize;
 n:=random(1000)+1;
 writeln(n);
 for i:=1 to n do
  writeln(random(maxlongint)+1);
 close(output);
end.

 

最核心的部分就是这里

新建一个文本文档,后缀名改为“.bat”

在里面打

:loop
maker.exe
a.exe
b.exe
fc o1.txt o2.txt
if errorlevel 1 goto end
goto loop

:end

 

dos语言:loop//循环
maker.exe//运行 数据生成器
a.exe//运行 正确程序
b.exe//运行 待检测程序
fc o1.txt o2.txt//比较 两个程序的输出结果
if errorlevel 1 goto end//如果 有错误(两个输出文件不一样) 就跳到end

goto loop//跳到loop
:end

 

或者还可以这样写

:loop
maker.exe>in.txt
a.exeo1.txt
b.exeo2.txt
fc o1.txt o2.txt
if errorlevel 1 goto end

goto loop
:end

 

要是这样写,a  maker  三个程序中都不能些文件读入/输出 

:loop
maker.exe>in.txt//运行 数据生成器 把结果输出到 in.txt
a.exeo1.txt//运行 正确程序 读入为 in.txt 输出为 o1.txt
b.exeo2.txt//运行 待检测程序 读入为 in.txt 输出为 o2.txt
fc o1.txt o2.txt
if errorlevel 1 goto end

goto loop
:end


注意:

1.程序检测的是执行程序,而不是源程序。所以每改一次源程序都要编译一次。

2.dos中貌似不识别 .in .out 文件,所以要用 .txt

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值