一个刷题模拟器,一定要有题,题目从这里下载
欢迎大家提供新题目(请把题目文件夹压缩成zip后发给我chengyixuan130812@163.com),我会定期更新的。
题目格式:
题目编号
nums.txt(评测点个数)
题目描述.txt(题目描述)
1_in.txt(第1个测试点的输入)
1_out.txt(第1个测试点的输出)
……
n_in.txt(例如n=10,文件名为10_in.txt)
n_out.txt(例如n=10,文件名为10_out.txt)
下面是正文:
我把这个项目分成了几块,分别是:显示题目描述、编译程序、评测
最后我还做了一个“开始做题”的程序
先在你的工程里建一个文件夹,把题目和程序放在这个目录下。注意,最后编译的时候请在目录下编译
先把要做的题号放在了“题号.txt”文件里
这样显示题目描述就简单了,只要把题号读出来,再找到文件夹里的“题目描述.txt”并输出就好了
题目描述.cpp
windows:
#include <iostream>
#include <fstream>
using namespace std;int main()
{ifstream fin("\\题号.txt");string num;fin >> num;fin.close();fin.open("\\" + num + "\\题目描述.txt");string s;while(getline(fin,s)){cout << s << endl;}return 0;
}
mac/linux:
#include <iostream>
#include <fstream>
using namespace std;int main()
{ifstream fin("./题号.txt");string num;fin >> num;fin.close();fin.open("./" + num + "/题目描述.txt");string s;while(getline(fin,s)){cout << s << endl;}return 0;
}
我把题目程序放在了test.cpp文件里
如果想要在终端编译程序,可以输入g++ -o main main.cpp(这里要编译的文件是main.cpp,而编译出来的文件是main/main.exe)
在程序里只要使用system("g++ -o main main.cpp");就能编译成功了
make.cpp
#include <iostream>
#include <cstdlib>
using namespace std;int main()
{system("g++ -o test test.cpp");return 0;
}
最后评测环节,把评测点读入到程序里,把它存在一个文件里,与评测点的输出做比较,如果相同那么就对了,我结果记录在一个“检测结果.txt”文件里
windows:
#include <bits/stdc++.h>
using namespace std;int main()
{ifstream fin("题号.txt");string ti;fin >> ti;fin.close();fin.open(ti + "\\nums.txt");int nums;fin >> nums;fin.close();int cnt = 0;system("./make.exe");ofstream fout("检测情况.txt",ios::trunc);for(int i = 1;i <= nums;i++){string dic = "test_" + to_string(i) + ".out";freopen(dic.c_str(),"w",stdout);string s = ti + "\\" + to_string(i) + "_in.txt";freopen(s.c_str(),"r",stdin);system("./test");fclose(stdin);ifstream fin1(dic);ifstream fin2(ti + "\\" + to_string(i) + "_out.txt");string s1,s2;bool flag = true;while(getline(fin1,s1) && getline(fin2,s2)){if(s1 != s2){flag = false;}}fout << to_string(i) << ":";if(flag){fout << "AC" << endl;cnt++;}elsefout << "WA" << endl;fclose(stdout);}printf("你得到了%d分",(int)floor(1.0 * cnt / nums));return 0;
}
mac/linux:
#include <bits/stdc++.h>
using namespace std;int main()
{ifstream fin("./题号.txt");string ti;fin >> ti;fin.close();fin.open(ti + "/nums.txt");int nums;fin >> nums;fin.close();int cnt = 0;system("./make");ofstream fout("./检测情况.txt",ios::trunc);for(int i = 1;i <= nums;i++){string dic = "./test_" + to_string(i) + ".out";freopen(dic.c_str(),"w",stdout);string s = "./" + ti + "/" + to_string(i) + "_in.txt";freopen(s.c_str(),"r",stdin);system("./test");fclose(stdin);ifstream fin1(dic);ifstream fin2("./" + ti + "/" + to_string(i) + "_out.txt");string s1,s2;bool flag = true;while(getline(fin1,s1) && getline(fin2,s2)){if(s1 != s2){flag = false;}}fout << to_string(i) << ":";if(flag){fout << "AC" << endl;cnt++;}elsefout << "WA" << endl;fclose(stdout);}printf("你得到了%d分",(int)floor(1.0 * cnt / nums));return 0;
}
最后把所有文件编译即可