我一直覺得出OI題是件快樂的事,但造資料、敲std是件麻煩的事,
于是,我寫下了這樣兩段代碼……
//makedata.h 2020.12.13
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ofstream infile,outfile;
string name="data";
int times=10;
void file(int tp){
char*inname=new char[filename.length()+6];
infile.close();
sprintf(inname,"%s%02d.in",filename.c_str(),tp);
infile.open(inname);
char*outname=new char[filename.length()+7];
outfile.close();
sprintf(outname,"%s%02d.out",filename.c_str(),tp);
outfile.open(outname);
}
#define num(a,b) (rand()%(a-b+1)+a)
int make(int tp);
int main(){
srand(unsigned(time(NULL)));
for(int tp=1;tp<=testtimes;++tp)file(tp),make(tp);
return 0;
}
//main.cpp 2020.12.13
make(int tp){
infile<<tp;
outfile<<2*tp;
}
是不是很短?(無論是頭檔案還是主程式,它都比CarYon簡潔得多,)
它的作用是生成下面這道題的資料檔案:
輸入正整數a,求2*a的值(1<=a<=10),
那么,效果究竟怎么樣呢?

絕了嗎?絕了!
稍微翻翻源代碼,你就可以掌握它的基本使用方法:
1.修改in/out檔案名:
name="你要的檔案名";
2.修改測驗點數目:
times=你要的測驗點數目;
3.輸出當前測驗點編號:
cout<<tp<<endl;
4.寫入資料到輸入檔案:
infile<<資料<<endl;
5.寫入資料到輸出檔案:
outfile<<資料<<endl;
7.生成(a,b)區間的亂數:
變數名=num(a,b);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/234006.html
標籤:其他
