社区讨论
对拍代码求调
灌水区参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @lxmt8fnq
- 此快照首次捕获于
- 2024/06/20 13:17 2 年前
- 此快照最后确认于
- 2024/06/20 17:35 2 年前
今天第一次写对拍代码,结果出问题了,这里能找到大佬吗?
CPP//对拍
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace chrono;
// 定义ANSI颜色代码
const string GREEN = "\033[1;32m";
const string RED = "\033[1;31m";
const string PURPLE = "\033[1;35m";
const string RESET = "\033[0m";
int main()
{
int t = 0; // 初始化测试次数计数器
int flag=0;//记录AC但TLE的组数;
// 指定结果文件路径
const string result_path = "D/CODE/DEV C++/M7/对拍/Answer/result.out";
ofstream result(result_path);
while(true)
{
cout<<"TEST: "<<++t<<endl;
//生成测试数据并写入数据文件
system("D:/CODE/DEV C++/M7/对拍/Code/dataMaker.exe>D:/CODE/DEV C++/M7/对拍/Answer/data.in") ;
//读取数据文件,并记录测试代码运行时间
auto start_testCode = high_resolution_clock::now();
system("D:/CODE/DEV C++/M7/对拍/Code/testCode.exe<D:/CODE/DEV C++/M7/对拍/Answer/data.in>D:/CODE/DEV C++/M7/对拍/Answer/testAnswer.out");
auto end_testCode = high_resolution_clock::now();
duration<double> elapsed_testCode = end_testCode - start_testCode;
//读取数据文件,并记录标准代码运行时间
auto start_standCode = high_resolution_clock::now();
system("D:/CODE/DEV C++/M7/对拍/Code/standCode.exe<D:/CODE/DEV C++/M7/对拍/Answer/data.in>D:/CODE/DEV C++/M7/对拍/Answer/standAnswer.out");
auto end_standCode = high_resolution_clock::now();
duration<double> elapsed_standCode = end_standCode - start_standCode;
//输出程序运行时间
cout<<"测试代码运行:"<< elapsed_testCode.count() << "ms" << endl;
cout<<"标准代码运行:"<< elapsed_standCode.count()<< "ms" << endl;
//输出结果:
cout<<"结果:";
//比较结果
if (system("fc D:/CODE/DEV C++/M7/对拍/Answer/testAnswer.out D:/CODE/DEV C++/M7/对拍/Answer/standAnswer.out > diff.log"))
{
// 输出红色的“WrongAnswer”,表示两个输出文件不一致
cout << RED << "WrongAnswer" << RESET;
// 将错误的测试数据写入 result.out 文件
result << "数据:" << endl;
ifstream data_in("D:/CODE/DEV C++/M7/对拍/Answer/data.in");
result << data_in.rdbuf(); // 读取并写入测试数据内容
data_in.close();
result << "测试结果:" << endl;
ifstream test_result("D:/CODE/DEV C++/M7/对拍/Answer/testAnswer.out");
result << test_result.rdbuf(); // 读取并写入测试结果内容
test_result.close();
result << "标准结果:" << endl;
ifstream std_result("D:/CODE/DEV C++/M7/对拍/Answer/standAnswer.out");
result << std_result.rdbuf(); // 读取并写入标准结果内容
std_result.close();
result << "对比结果:WA" << endl;
//进一步检查是不是超时了
if(elapsed_testCode.count() > 2000)
{
//接着输出TLE;
cout<<" + "<< PURPLE << "TLE" << RESET << endl<<endl;
result <<" + TLE" << endl;
}
cout<<endl<<endl;
break; // 退出循环
}
else
{
//结果正确
cout<<GREEN<<"Accepted"<<RESET;
//检查是否超时
if(elapsed_testCode.count() > 2000)
{
//接着输出TLE;
cout<<" + "<< PURPLE << "TLE" << RESET << endl<<endl;
//记录超时数据
result << "数据:" << endl;
ifstream data_in("D:/CODE/DEV C++/M7/对拍/Answer/data.in");
result << data_in.rdbuf(); // 读取并写入测试数据内容
data_in.close();
result << "测试结果:" << endl;
ifstream test_result("D:/CODE/DEV C++/M7/对拍/Answer/testAnswer.out");
result << test_result.rdbuf(); // 读取并写入测试结果内容
test_result.close();
result << "标准结果:" << endl;
ifstream std_result("D:/CODE/DEV C++/M7/对拍/Answer/standAnswer.out");
result << std_result.rdbuf(); // 读取并写入标准结果内容
std_result.close();
result << "对比结果:AC + TLE" << endl;
flag++;
}
cout<<endl<<endl;
}
if(flag==10)break;
}
result.close(); // 关闭结果记录文件
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...