.net process 调用G++编译器执行CPP编译,模拟ACM在线评判
来源:互联网 发布:地牢探测器JS 编辑:程序博客网 时间:2024/06/03 02:41
ACM在线评判,需自动判断程序正确性,需两个步骤
1、调用对应的编译器编译学生提交的源代码
2、执行编译好的程序,输入测试数据,运行判断运行结果是否是预期结果
-------------------------------------待测试用户代码max-----------------------------------------------------
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int a,b;
scanf("%d %d",&a,&b);
printf("%d",a>b?a:b);
return 0;
}
------------------------------模拟评判代码------------------------------------
private void button1_Click(object sender, EventArgs e)
{
if (Compile("max"))//如果编译max程序成功
{
bool result = Test("max", "4 5", "5"); //对MAX程序测试,送入测试数据4 5,预期结果 5
if (result) MessageBox.Show("ok");
else MessageBox.Show("err");
}
}
///自动编译cpp代码
//filename待编译CPP文件名
bool Compile(string fileName)
{
fileName = "max";
string command = @"D:\DEV-CPP\Bin\g++.exe"; //编译器G++
Process p = new Process();
p.StartInfo.FileName = command; //确定程序名
p.StartInfo.Arguments = @"D:\DEV-CPP\Bin\max.cpp -o D:\DEV-CPP\Bin\max.exe"; //确定程式命令行
p.StartInfo.UseShellExecute = false; //Shell的使用
p.StartInfo.RedirectStandardInput = true; //重定向输入
p.StartInfo.RedirectStandardOutput = true; //重定向输出
p.StartInfo.RedirectStandardError = true; //重定向输出错误
p.StartInfo.CreateNoWindow = false; //设置置不显示示窗口
p.Start();
textBox1.Text = p.StandardError.ReadToEnd(); //输出出流取得命令行结果果
p.WaitForExit();
if (textBox1.Text == "") return true;//如果无错误输出,则编译成功
return false;
}
//自动测试代码
//filename:被测试cpp的EXE文件名
//testData测试数据
//result 预期测试结果
bool Test(string fileName,string testData,string result)
{
fileName = "max";
string command = @"D:\DEV-CPP\Bin\max.exe";
Process p = new Process();
p.StartInfo.FileName = command; //确定程序名
p.StartInfo.UseShellExecute = false; //Shell的使用
p.StartInfo.RedirectStandardInput = true; //重定向输入
p.StartInfo.RedirectStandardOutput = true; //重定向输出
p.StartInfo.RedirectStandardError = true; //重定向输出错误
p.StartInfo.CreateNoWindow = false; //设置置不显示示窗口
p.Start();
p.StandardInput.WriteLine(testData);
string realResult = p.StandardOutput.ReadToEnd(); //取得实际结果realResult
//输出出流取得命令行结果果
p.WaitForExit();
if (result == realResult) return true;
return false;
}
}
- .net process 调用G++编译器执行CPP编译,模拟ACM在线评判
- 一种ACM评判内核简易实现 使用C# WEB调用C++编译器的方法
- 国内ACM 在线评判系统大荟萃
- ACM在线评判系统核心代码
- 编译器编译main.cpp
- Dev C++ 与 ACM/ICPC程序设计在线评判系统
- g++ 编译几个cpp
- 由成幻OnlineJudge学习如何做自己的Acm-Icpc在线评判系统-5.在线编译与测试系统代码粗解
- g++编译器编译过程
- makefile调用、编译、执行过程(verilog&cpp)
- 当编译器编译main.cpp,
- ACM g++编译器命令详解
- 在asp.net中调用process.start执行程序
- 源码:JAVA在线编译器模拟
- ACM 评判结果
- g++编译器编译多源文件
- 显示调用析构函数被g++编译器优化掉不执行
- g++编译 链接 执行
- JS学习之道:JS 中如何判断 undefined 和 null
- ios网络编程(4)
- QT sizeHint 及 Policy的用法
- REST with Java (JAX-RS) using Jersey - Tutorial(使用REST的Jersey与Java(JAX-RS)-教程)
- 关于SAE的Email到达率很低的解决方案
- .net process 调用G++编译器执行CPP编译,模拟ACM在线评判
- 定义结构体时变量名后的冒号和数字
- JS加入收藏,Jquery更改透明度
- Unity3d 倒序播放动画
- Android数据库ORMlite框架翻译系列(第二章:part 1)
- Linux Xshell4下编译安装php mongodb扩展经验分享
- navicat for mysql 快捷键
- matlab学习笔记001之与本项目相关的matlab基础
- Tomcat默认目录修改和配置虚拟目录