// 新テストケースverify用 // Rime使えばよかったことにさっき気がついた #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; void main_(); signed main() { ios::sync_with_stdio(false); main_(); return 0; } #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) template inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); } template inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); } typedef long long ll; int const inf = 1<<29; int command(string s) { return system(s.c_str()); } string get_suffix(string s) { string ret; for(int i=(int)s.size()-1; i>=0; i--) { if(s[i] == '.') { break; } ret.push_back(s[i]); } reverse(all(ret)); return ret; } int compile(string fname) { auto suffix = get_suffix(fname); if(suffix == "cpp" || suffix == "cxx") { return command("clang++ " + fname + " -std=c++1z -o __" + fname + "_exe"); } else if(suffix == "java") { return command("javac " + fname); } else { cout << "undefined suffix: " << suffix << endl; return -1; } return 0; } int run_program(string fname, string redirect, int index) { auto suffix = get_suffix(fname); if(suffix == "cpp" || suffix == "cxx") { return command("./__" + fname + "_exe < " + redirect + " > __" + fname + "_out_" + to_string(index)); } else if(suffix == "java") { return command("java " + fname.substr(0, fname.size() - 5) + " < " + redirect + " > __" + fname + "_out_" + to_string(index)); } else { cout << "undefined suffix: " << suffix << endl; return -1; } return 0; } void main_() { vector input_fnames; namespace fs = boost::filesystem; const fs::path path("new_input"); BOOST_FOREACH(const fs::path& p, make_pair(fs::directory_iterator(path), fs::directory_iterator())) { if (!fs::is_directory(p)) { auto name = p.filename().string(); if(name[0] == '.') { continue; } input_fnames.push_back(path.string() + "/" + name); } } string ac_code; cin >> ac_code; vector codes; for(string s; cin >> s; codes.push_back(s)); cout << "Compiling " << ac_code << "(AC code)" << endl; assert(0 == compile(ac_code)); for(auto && f: codes) { cout << "Compiling " << f << endl; assert(0 == compile(f)); } rep(in_idx, input_fnames.size()) { cout << "Runnning " << ac_code << "(AC code) with " << input_fnames[in_idx] << endl; run_program(ac_code, input_fnames[in_idx], in_idx); } rep(code_idx, codes.size()) { rep(in_idx, input_fnames.size()) { cout << "Runnning " << codes[code_idx] << " with " << input_fnames[in_idx] << endl; run_program(codes[code_idx], input_fnames[in_idx], in_idx); } } vector pass_count(codes.size()); map input_success_rate; // input_fnames'index -> rate rep(code_idx, codes.size()) { rep(in_idx, input_fnames.size()) { int s = 0 == command("diff __" + ac_code + "_out_" + to_string(in_idx) + " __" + codes[code_idx] + "_out_" + to_string(in_idx)); pass_count[code_idx] += s; input_success_rate[in_idx] += (double)s / codes.size(); } } rep(i, codes.size()) { cout << codes[i] << endl; cout << "Passed " << pass_count[i] << " / " << input_fnames.size() << endl << endl; } cout << "Input success rate" << endl; for(auto && e: input_success_rate) { cout << input_fnames[e.first] << ": " << setprecision(10) << e.second * 100.0 << "%" << endl; } #define TRY try { #define CATCH } catch(fs::filesystem_error& ex) { cout << ex.what() << endl; throw; } // remove files TRY fs::remove("__" + ac_code + "_exe"); CATCH rep(i, input_fnames.size()) { TRY fs::remove("__" + ac_code + "_out_" + to_string(i)); CATCH } rep(i, codes.size()) { TRY fs::remove("__" + codes[i] + "_exe"); CATCH rep(j, input_fnames.size()) { TRY fs::remove("__" + codes[i] + "_out_" + to_string(j)); CATCH } } }