Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> // cout
- #include <string> // string
- #include <vector> // vector
- #include <fstream> // fille >> <<
- #include <sstream> // ostringstream
- #include <time.h> // time
- #include "lxc.h"
- #include <random>
- using namespace std;
- void run(string command)
- {
- system(command.c_str());
- }
- void run(string command, int i)
- {
- command += " > console.linux.txt";
- system(command.c_str());
- }
- class v
- {
- private:
- string str, answer;
- public:
- v(string answer_, string str_)
- {
- str = str_;
- answer = answer_;
- }
- /// checker
- bool vec() // G A T E | GATE (split)
- {
- vector <char> vanswer;
- vector <char> vstr;
- for (char c : answer)
- if (c != ' ')vanswer.push_back(c);
- for (char c : str)
- if (c != ' ')vstr.push_back(c);
- if (vstr.size() != vanswer.size())
- return false;
- for (int i = 0; i < vstr.size(); i++)
- if (vstr[i] != vanswer[i])
- return false;
- return true;
- }
- bool str1() // GATE | GATE
- {
- return ((str == answer) ? true : false);
- }
- bool str1_() // GATE_ | GATE
- {
- return ((str == answer + " " || str == answer) ? true : false);
- }
- bool no() // no fix a+n 1 || 1!=1
- {
- return ((str != answer && str != answer + " ") ? true : false);
- }
- };
- void readFile(string fileName, string &str)
- {
- std::ifstream in(fileName.c_str(), ios::in);
- ostringstream out;
- str.clear();
- out << in.rdbuf();
- out.str().swap(str);
- in.close();
- }
- int main()
- {
- string language = "python3";
- lxc c;
- ifstream property("0001/property.txt", ios::in); // настройки задачи
- ofstream log("log.txt", ios::out);
- int SIZET;
- string infile, outfile;
- property >> SIZET >> infile >> outfile;
- string testoutput, testinput, output;
- log << "\n{test;input;trueanswer;answer;true/false}\n";
- if (language == "g++")
- system("g++ code.cpp -o code.o"); // gcc 7.3.0
- for (int i = 1; i <= SIZET; i++)
- {
- string container = "b" + to_string(i);
- c.start_container(container);
- readFile(("0001/output/" + to_string(i) + ".txt"), testoutput);
- readFile(("0001/input/" + to_string(i) + ".txt"), testinput);
- c.transfer_to(container,"/home/lxc/0001/input/" + to_string(i) + ".txt",infile);
- if (language == "g++")
- {
- c.transfer_to(container,"code.o","code.o");
- run("sudo lxc-attach " + container + " ./code.o");
- }
- else if (language == "python3")
- {
- c.transfer_to(container,"code.py","code.py");
- run("sudo lxc-attach " + container + " python3 code.py");
- }
- c.transfer_from(container,outfile,"console.linux.txt");
- readFile("console.linux.txt",output);
- cout << i << ";" << testinput << ";" << testoutput << ";" << output << ";" << "\n";
- }
- /*
- random_device rd;
- mt19937 gen(rd());
- for (int i = 1; i <= 20; ++i) {
- ofstream out("0001/output/" + to_string(i) + ".txt",ios::out);
- ofstream in("0001/input/" + to_string(i) + ".txt",ios::out);
- long long a =gen() % 1000;
- long long b = gen() %1000;
- in << a << " " << b; // print the raw output of the generator.
- out << a + b;
- in.close();
- out.close();
- }
- */
- log.close();
- property.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement