Advertisement
Guest User

main.cpp

a guest
Jun 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.16 KB | None | 0 0
  1. #include <iostream> // cout
  2. #include <string>   // string
  3. #include <vector>   // vector
  4. #include <fstream>  // fille >> <<
  5. #include <sstream>  // ostringstream
  6. #include <time.h>   // time
  7. #include "lxc.h"
  8. #include <random>
  9. using namespace std;
  10. void run(string command)
  11. {
  12.     system(command.c_str());
  13. }
  14. void run(string command, int i)
  15. {
  16.     command += " > console.linux.txt";
  17.     system(command.c_str());
  18. }
  19.  
  20. class v
  21. {
  22. private:
  23.     string str, answer;
  24. public:
  25.     v(string answer_, string str_)
  26.     {
  27.         str = str_;
  28.         answer = answer_;
  29.     }
  30.  
  31.     /// checker
  32.     bool vec() // G A T E | GATE (split)
  33.     {
  34.         vector <char> vanswer;
  35.         vector <char> vstr;
  36.         for (char c : answer)
  37.             if (c != ' ')vanswer.push_back(c);
  38.         for (char c : str)
  39.             if (c != ' ')vstr.push_back(c);
  40.         if (vstr.size() != vanswer.size())
  41.             return false;
  42.         for (int i = 0; i < vstr.size(); i++)
  43.             if (vstr[i] != vanswer[i])
  44.                 return false;
  45.         return true;
  46.     }
  47.     bool str1() // GATE | GATE
  48.     {
  49.         return ((str == answer) ? true : false);
  50.     }
  51.     bool str1_() // GATE_ | GATE
  52.     {
  53.         return ((str == answer + " " || str == answer) ? true : false);
  54.     }
  55.     bool no() // no fix a+n 1 || 1!=1
  56.     {
  57.         return ((str != answer && str != answer + " ") ? true : false);
  58.     }
  59. };
  60. void readFile(string fileName, string &str)
  61. {
  62.     std::ifstream in(fileName.c_str(), ios::in);
  63.     ostringstream out;
  64.     str.clear();
  65.     out << in.rdbuf();
  66.     out.str().swap(str);
  67.     in.close();
  68. }
  69. int main()
  70. {
  71.    
  72.  
  73.     string language = "python3";
  74.  
  75.     lxc c;
  76.    
  77.     ifstream property("0001/property.txt", ios::in); // настройки задачи
  78.     ofstream log("log.txt", ios::out);
  79.    
  80.     int SIZET;
  81.     string infile, outfile;
  82.     property >> SIZET >> infile >> outfile;
  83.     string testoutput, testinput, output;
  84.  
  85.     log << "\n{test;input;trueanswer;answer;true/false}\n";
  86.  
  87.     if (language == "g++")
  88.         system("g++ code.cpp -o code.o"); // gcc 7.3.0
  89.    
  90.    
  91.     for (int i = 1; i <= SIZET; i++)
  92.     {  
  93.         string container = "b" + to_string(i);
  94.         c.start_container(container);
  95.        
  96.         readFile(("0001/output/" + to_string(i) + ".txt"), testoutput);    
  97.         readFile(("0001/input/" + to_string(i) + ".txt"), testinput);
  98.  
  99.         c.transfer_to(container,"/home/lxc/0001/input/" + to_string(i) + ".txt",infile);
  100.        
  101.         if (language == "g++")
  102.             {
  103.                 c.transfer_to(container,"code.o","code.o");
  104.                 run("sudo lxc-attach " + container + " ./code.o");
  105.             }
  106.         else if (language == "python3")
  107.             {
  108.                 c.transfer_to(container,"code.py","code.py");
  109.                 run("sudo lxc-attach " + container + " python3 code.py");
  110.             }
  111.         c.transfer_from(container,outfile,"console.linux.txt");
  112.         readFile("console.linux.txt",output);
  113.  
  114.         cout << i << ";" << testinput << ";" << testoutput << ";" << output << ";" << "\n";
  115.        
  116.  
  117.  
  118.     }
  119.    
  120.     /*
  121.     random_device rd;    
  122.     mt19937 gen(rd());  
  123.  
  124.     for (int i = 1; i <= 20; ++i) {  
  125.         ofstream out("0001/output/" + to_string(i) + ".txt",ios::out);
  126.         ofstream in("0001/input/" + to_string(i) + ".txt",ios::out);
  127.         long long a =gen() % 1000;
  128.         long long b = gen() %1000;
  129.         in << a << " " << b; // print the raw output of the generator.  
  130.         out << a + b;
  131.         in.close();
  132.         out.close();
  133.     }  
  134.     */
  135.     log.close();
  136.        
  137.     property.close();
  138.  
  139.     return 0;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement