我一直覺得出OI題是件快樂的事,但造資料、敲std是件麻煩的事,
于是,我寫下了這樣一段代碼……(2020.12.12 21:45更新)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ofstream infile,outfile;
string filename="data";
int testtimes=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);
}
ll random(ll a,ll b){
return 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;
}
這是data.cpp的代碼,是不是很短?
它的作用是生成下面這道題的資料檔案:
輸入正整數a,求2*a的值(1<=a<=10),
那么,效果究竟怎么樣呢?

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