[C++ && Python]简单模拟代码评测系统

来源:互联网 发布:苹果蓝牙共享网络 编辑:程序博客网 时间:2024/06/02 06:56

简单模拟代码评测系统

本实现版本使用python调用系统命令(compiler.py)完成代码的编译,输入,输出,用judge.cpp程序判断测试文件与标准程序之间的输入是否有差别,从而判断是否为正确程序代码。但这里还有一个问题,就是没有随机生成的输入内容,这个部分需要自己编写。此程序大概简化模拟了eden评测系统的原理。对于平时研究自己的代码与网络代码之间的正确与否有一定的帮助。
代码下载

核心代码

import osos.system("g++ Standard.cpp -o Standard")os.system("g++ test.cpp -o test")os.system("./Standard < input > output_Standard")os.system("./test < input > output_answer")os.system("g++ judge.cpp -o judge")os.system("./judge")
#include <iostream>#include <string>#include <fstream>#include <string.h>#include <stdlib.h>using namespace std;int main(int argc, char const *argv[]){    string standard;    ifstream file_Standard ("output_Standard");    if (!file_Standard.is_open())    {        cout << "fail" << endl;    }    ifstream file_answer ("output_answer");    char Standard_answer[100];    char Test_answer[100];    while (!file_answer.eof()) {        file_Standard.getline(Standard_answer, 100);        file_answer.getline(Test_answer, 100);        if (strcmp(Standard_answer, Test_answer))        {            cout << Standard_answer << endl;            cout << Test_answer << endl;            cout << "wrong" << endl;            return 0;        }    }    cout << "true" << endl;    return 0;}

测试代码

#include <iostream>#include <map>#include <set>using namespace std;int main() {    multimap<string, string> Q;    int n;    cin >> n;    while (n--) {        string input1, input2;        cin >> input1 >> input2;        if (Q.find(input1) == Q.end() || Q.find(input1)->second != input2) {            Q.insert(make_pair(input1, input2));        }    }    string address;    cin >> address;    multimap<string, string>::iterator iter = Q.begin();    int flag = 0;    while (iter != Q.end()) {        if (iter->second == address) {            flag = 1;            break;        }        iter++;    }    iter = Q.begin();    if (flag == 1) {        cout << address;        cout << " ==> [ ";        multimap<string, string>::iterator iters = Q.begin();        set<string> answer;        while (iters != Q.end()) {            if (iters->second == address) {                answer.insert(iters->first);            }            iters++;        }        for (set<string>::iterator iter = answer.begin();        iter != answer.end(); iter++) {            cout << *iter << " ";        }        cout << "]" << endl;    } else {        cout << "no Q" << endl;    }    string number;    cin >> number;    if (Q.find(number) != Q.end()) {        cout << number;        cout << " ==> [ ";        multimap<string, string>::iterator iterss = Q.begin();        set<string> answer;        while (iterss != Q.end()) {            if (iterss->first == number) {                answer.insert(iterss->second);            }            iterss++;        }        for (set<string>::iterator iter = answer.begin();        iter != answer.end(); iter++) {            cout << *iter << " ";        }        cout << "]" << endl;    } else {        cout << "no ip" << endl;    }    return 0;}
#include <iostream>#include <map>#include <set>#include <string>using namespace std;int main() {  map<string, set<string> > ip2qq;  map<string, set<string> > qq2ip;  int n;  string Q, ip;  cin >> n;  while (n--) {    cin >> Q >> ip;    ip2qq[ip].insert(Q);    qq2ip[Q].insert(ip);  }  map<string, set<string> >::iterator it;  set<string>::iterator its;  cin >> ip;  if (ip2qq.find(ip) == ip2qq.end()) {    cout << "no Q" << endl;  } else {    cout << ip <<  " ==> [ ";    for (its = ip2qq[ip].begin(); \         its != ip2qq[ip].end(); its++) {      cout << *its << " ";    }    cout << "]" << endl;  }  cin >> Q;  if (qq2ip.find(Q) == qq2ip.end()) {    cout << "no ip" << endl;  } else {    cout << Q <<  " ==> [ ";    for (its = qq2ip[Q].begin(); \         its != qq2ip[Q].end(); its++) {      cout << *its << " ";    }    cout << "]" << endl;  }  return 0;}

output_Standard

192.168.1.45 ==> [ 10258279640 10258279649 ]10258279649 ==> [ 192.168.1.45 ]

output_answer

192.168.1.45 ==> [ 10258279640 10258279649 ]10258279649 ==> [ 192.168.1.45 ]

input

510258279649 192.168.1.4510258279649 192.168.1.4510258279643 192.168.1.410258279640 192.168.1.4510258279641 192.168.1.30192.168.1.4510258279649
0 0
原创粉丝点击