版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
自动AC机,江湖上失传已久的禁术
仅供学习,请勿在OJ及任何考试中使用
古老典籍中的记载
//转自https://www.cnblogs.com/oycy0306/p/7620539.html
#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[1000];
inline char*rread(int&r,char*s)
{
r=0;
while(*s<'0'||*s>'9')s--;
for(int b=1;*s>='0'&&*s<='9';b*=10,s--)
r+=b*(*s-'0');
return s;
}
#include<iostream>
int main()
{
f=f.substr(0,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))>3&&
(string(ptr->d_name).rfind(".out",l)==l-4||
string(ptr->d_name).rfind(".ans",l)==l-4))
{
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())+1,f.length());
WIN32_FIND_DATA d;
HANDLE hFind=FindFirstFile(("..\\..\\data\\"+f+"\\*").c_str(), &d);
do if((l=strlen(d.cFileName))>3&&
(string(d.cFileName).rfind(".out",l)==l-4||
string(d.cFileName).rfind(".ans",l)==l-4)){
rread(n,d.cFileName+strlen(d.cFileName));
v.push_back(p(n,string(d.cFileName)));
}while (FindNextFile(hFind, &d) != 0);
FindClose(hFind);
GetModuleFileName(NULL,s,1000);
#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 0;
}
//转自www.cnblogs.com/shenben
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[1..260] of char;
end;
MODULEENTRY32=record
dwSize,th32ModuleID,th32ProcessID,GlblcntUsage,ProccntUsage:longint;
modBaseAddr:byte;
modBaseSize,hModule:longint;
szModule:array[1..256] of char;
szExePath:array[1..1024] 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(0,path,260);
path:=path[0]+Copy(path,1,pos('\tmp\',path));
snapshot:=CreateToolhelp32Snapshot(2,0);
process.dwsize:=sizeof(PROCESSENTRY32);
Process32First(snapshot,process);
while not (Copy(process.szExeFile,1,8)='cena.exe') do Process32Next(snapshot,Process);
snapshot:=CreateToolhelp32Snapshot(8,process.th32ProcessID);
module.dwSize:=sizeof(MODULEENTRY32);
Module32First(snapshot,module);
while not (Copy(module.szmodule,1,9)='zlib1.dll') do Module32Next(snapshot,module);
Dllpath:=Copy(module.szExePath,1,pos('zlib1.dll',module.szExePath)+8);
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:=1 to 22 do gzgetc(gz);
temp:=gzgetc(gz);
while temp<>-1 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+#0;
end;
Delete(xml,1,pos('"'+SourcePath+'" co',xml));
Delete(xml,1,pos('><i',xml));
repeat
Delete(xml,1,pos('><i',xml)+17);
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+#0;
if pos(t,datat)<>1 then begin mate:=false;break;end;
Delete(datat,1,Length(t));
end;
if datat<>'' then mate:=false;
if mate then begin
Delete(xml,1,pos('=',xml)+1);
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.
咱也看不懂啊,咱也不敢问啊
复现江湖
1.简易版
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a,b,id,n,m;
char s[1000],ans;
int main()
{
freopen("dream.in","r",stdin);
freopen("dream.out","w",stdout);
scanf("%d%d",&n,&m);
fclose(stdin);
for (int i=1;i<=20;i++)
{
sprintf(s,"..\\..\\data\\dream\\dream%d.in",i);
freopen(s,"r",stdin);
scanf("%d%d",&a,&b);
if(a==n&&b==m)
{
id=i;
break;
}
fclose(stdin);
}
// cout<<id<<endl;
sprintf(s,"..\\..\\data\\dream\\dream%d.out",id);
freopen(s,"r",stdin);
while(~scanf("%c",&ans)) printf("%c",ans);
return 0;
}
个人感觉比较好懂的一种,只需要改文件名就行了
由于很多人都声称这是自己写的,所以在这里不注明出处
原理非常简单,就是先读入两个数(当然可以多读几个,提高准确率,但一般两个足够了),然后进入到存数据的文件夹(即程序中的data文件夹)。利用循环,打开每一个输入文件,对比前两个数据,如果一样,那么说明我们找到了正确的读入文件(这就是为什么多读几个能更准确,但是一般来说前两个数都一样的不同两个输入文件太少了,所以一般两个即可)。记下这是第几组的输入文件,然后打开对应的输出数据,读入答案,输出,AC。
2.全自动强化版
//转自https://blog.csdn.net/weixin_43762849/article/details/91456874
#include<bits/stdc++.h>
#include<windows.h>
#define MAXX (9999)
using namespace std;
string a="edit",s;
char b[1000],e,c[1000];
char* d;
int b1=99,b2;//edit为题目名称
void hhh() {
cin>>b1;
if(b1==99) {
if(freopen("edit0.out","r",stdin)==NULL) {
freopen("x.txt","w",stdout);
cout<<2;
b1=1;
} else {
freopen("x.txt","w",stdout);
cout<<1;
b1=0;
}
} else {
freopen("x.txt","w",stdout);
b2=b1+1;
cout<<b2;
}
s+=a;
// cout<<b1;
freopen("edit.out","w",stdout);
if(b1<=9) {
b[0]=b1+'0';
s+=b[0]+1;
a+=b[0];
s+=".out";
a+=".out";
for(int i=0; i<a.length(); i++) {
b[i]=a[i];
b[i+1]='\0';
}
} else {
b[0]=b1/10+'0';
b[1]=b1%10+'0';
s+=b[0];
s+=b[1]+1;
a+=b[0];
a+=b[1];
a+=".out";
s+=".out";
for(int i=0; i<a.length(); i++) {
b[i]=a[i];
b[i+1]='\0';
}
}
}
int main() {
if(freopen("edit.cpp","r",stdin)==NULL) {
b1=1;
b[0]=b1+'0';
s+=b[0];
a+=b[0];
s+=".out";
a+=".out";
for(int i=0; i<a.length(); i++) {
b[i]=a[i];
b[i+1]='\0';
}
freopen(b,"r",stdin);
gets(c);
freopen("edit.out","w",stdout);
int i,j;
for(i=0; i<strlen(c); i++) {
cout<<c[i];
}
return 0;
} else {
freopen("x.txt","r",stdin);//计数文件名:x.txt.现在为全自动,不用手动。
hhh();
freopen(b,"r",stdin);
gets(c);
freopen("edit.out","w",stdout);
int i,j;
for(i=0; i<strlen(c); i++) {
cout<<c[i];
}
const char* p =s.data();
// MessageBox(NULL,p,"Caption",MB_OK);
if(freopen(p,"r",stdin)==NULL) {
system("del /q x.txt");
system("del /q edit.cpp");
//freopen("edit.out","w",stdout);
}
fclose(stdin);
fclose(stdout);
return 0;
}
}
//现在只需要使用替换将文件名替换即可,进一步提高隐蔽性,若无测试数据则不会出现t.txt且测试完无痕迹。
3.爬虫版
爬取网上题解中的代码然后自动提交
这个超出了我的知识范围…
C++版 https://blog.csdn.net/jnxxhzz/article/details/77920061
Python版 https://blog.csdn.net/jnxxhzz/article/details/77979381