#!/usr/bin/php <?php function judge($n) { $ma = 0; $mi = 1000; $s = 0; for ($i = 0; $i < $n; $i++) { $x = fgets(STDIN) + 0; if ($x < $mi) { $mi = $x; } if ($x > $ma) { $ma = $x; } $s += $x; } echo floor(($s - $ma - $mi) / ($n - 2)), "\n"; } while (1) { $n = fgets(STDIN); if ($n == 0) { break; } judge($n); }
if ($status == 0 || $status == true) { echo "<br/>"; echo $cmd . " success."; } else { echo "<br/>"; echo $cmd . " failed."; var_dump($status); } } echo "<br/>"; echo "下面为测试redis的php接口类iredis的各种命令."; $rf = new iredis(); $ipaddr = '192.168.122.10'; $port = 7000; $status = $rf->configure($ipaddr, $port); if ($rf->getStatus()) { echo "<br/>"; echo "connect server success"; } else { echo "<br/>"; echo "connect server:port ({$ipaddr}:{$port}) failed."; return; } $status = $rf->set('lenovo', 'shanghai777'); judge($status, "set"); # $status=$rf->del('lenovo'); # judge($status, "del"); # $status=$rf->hset('go','shanghai','e2e2'); # judge($status, "hset"); # $status=$rf->delete('go'); # judge($status, "delete");
require_once 'config_form.php'; $mform = new anti_plagiarism_config_form(); if ($fromform = $mform->get_data()) { $fromform->assignment = $id; $fromform->instance = $block; if (empty($antipla)) { insert_record('block_anti_plagiarism', $fromform); } else { $fromform->id = $antipla->id; update_record('block_anti_plagiarism', $fromform); if (isset($fromform->cleanall)) { delete_records('block_anti_plagiarism_pairs', 'apid', $antipla->id, 'confirmed', 0); } } $antipla = get_record('block_anti_plagiarism', 'assignment', $id); judge($fromform); } else { if (isset($antipla->id)) { $antipla->id = $id; } $mform->set_data($antipla); $mform->display(); } } else { //View or view confirmed only if (empty($antipla)) { if ($canjudge) { notice(get_string('noresults', 'block_anti_plagiarism'), $CFG->wwwroot . '/blocks/anti_plagiarism/view.php?id=' . $id . '&block=' . $block . '&action=config'); } else { notice(get_string('noresultsandwait', 'block_anti_plagiarism')); }
// If $judging is null, an error occurred; don't try to decode. if (!is_null($judging)) { $row = dj_json_decode($judging); } // nothing returned -> no open submissions for us if (empty($row)) { if (!$endpoints[$endpointID]["waiting"]) { logmsg(LOG_INFO, "No submissions in queue (for endpoint {$endpointID}), waiting..."); $endpoints[$endpointID]["waiting"] = TRUE; } continue; } // we have gotten a submission for judging $endpoints[$endpointID]["waiting"] = FALSE; logmsg(LOG_NOTICE, "Judging submission s{$row['submitid']} (endpoint {$endpointID}) " . "(t{$row['teamid']}/p{$row['probid']}/{$row['langid']}), id j{$row['judgingid']}..."); judge($row); // restart the judging loop } function judge($row) { global $EXITCODES, $myhost, $options, $workdirpath; // Set configuration variables for called programs putenv('USE_CHROOT=' . (USE_CHROOT ? '1' : '')); putenv('SCRIPTTIMELIMIT=' . dbconfig_get_rest('script_timelimit')); putenv('SCRIPTMEMLIMIT=' . dbconfig_get_rest('script_memory_limit')); putenv('SCRIPTFILELIMIT=' . dbconfig_get_rest('script_filesize_limit')); putenv('MEMLIMIT=' . $row['memlimit']); putenv('FILELIMIT=' . $row['outputlimit']); putenv('PROCLIMIT=' . dbconfig_get_rest('process_limit')); $cpuset_opt = ""; if (isset($options['daemonid'])) {
function action_judge($task) { include 'module/judge/judge.php'; judge($task); }
function compileProgram($sourcefile, $sourcedir, $classfile, $class, $inputs, $args, $processname, $data, $problem_number, $file_input_title, $file_input_data, $file_output_data, $problem_timeout, $team) { @mkdir($sourcedir, 0755, true); $outputfile = "{$classfile}"; chdir("/tmp/{$processname}"); $handle = fopen($sourcefile, 'w+'); fwrite($handle, $data); fclose($handle); if ($file_input_data !== "") { $handle = fopen($file_input_title . '.in', 'w+'); fwrite($handle, $file_input_data); fclose($handle); } $conn = mysqli_connect(host, user, pw, db); $data = mysqli_real_escape_string($conn, $data); mysqli_close($conn); $compile_error = false; $runtime_error = false; $compile_data = proc_exec("javac -cp . {$sourcefile} 2>&1", "", "compile", $problem_timeout); if ($compile_data["output"] != "") { $compile_error = true; } #chdir(dirname(__FILE__)); #$exec_data = proc_exec("java -classpath ../classloader ContestJudge /tmp/$processname/ ".substr($classfile,0,strlen($classfile)-6), $inputs, "execute"); $exec_data = proc_exec("java -classpath {$sourcedir} {$class} {$args} 2>&1", $inputs, "execute", $problem_timeout); if ($exec_data["success"] === "false") { $conn = mysqli_connect(host, user, pw, db); $cur_time = date("Y-m-d H:i:s"); $query = "INSERT INTO submissions (id, team, problem, time, subid, code, output, success, error, real_output) VALUES (NULL, '{$team}', '{$problem_number}','{$cur_time}','{$processname}','{$data}','', 'No', 'Timeout', '{$file_output_data}')"; mysqli_query($conn, $query); mysqli_close($conn); return array("success" => "false", "error" => "Your program ran longer than the time alotted! Please make sure you don't go above the time limit. [Timeout error]"); } if (preg_match("/.?Exception in thread/", $exec_data["output"]) == 1) { $runtime_error = true; } exec("rm -rf /tmp/{$processname}*"); //compilation successful if ($compile_data["success"] === "true" && $exec_data["success"] === "true" && $compile_error === false && $runtime_error === false) { $conn = mysqli_connect(host, user, pw, db); $timestamp_a = $exec_data['timestamp']; $output_a = mysqli_real_escape_string($conn, $exec_data['output']); if (judge($file_output_data, $exec_data['output'])) { //correct answer $query = "INSERT INTO submissions (id, team, problem, time, subid, code, output, success, error, real_output) VALUES (NULL, '{$team}', '{$problem_number}','{$timestamp_a}','{$processname}','{$data}','{$output_a}', 'Yes', 'None', '{$file_output_data}')"; mysqli_query($conn, $query); mysqli_close($conn); return array("success" => "true", "time" => $exec_data['time']); } else { //incorrect answer $query = "INSERT INTO submissions (id, team, problem, time, subid, code, output, success, error, real_output) VALUES (NULL, '{$team}', '{$problem_number}','{$timestamp_a}','{$processname}','{$data}','{$output_a}', 'No', 'None', '{$file_output_data}')"; mysqli_query($conn, $query); mysqli_close($conn); return array("success" => "false", "error" => "Your output was incorrect!"); } } else { if ($compile_error) { $conn = mysqli_connect(host, user, pw, db); $cur_time = date("Y-m-d H:i:s"); $output_a = mysqli_real_escape_string($conn, $compile_data['output']); $query = "INSERT INTO submissions (id, team, problem, time, subid, code, output, success, error, real_output) VALUES (NULL, '{$team}', '{$problem_number}','{$cur_time}','{$processname}','{$data}','{$output_a}', 'No', 'Syntax', '{$file_output_data}')"; mysqli_query($conn, $query); mysqli_close($conn); return array("success" => "false", "error" => "Your program was unable to compile! Please check for syntax errors and resubmit. [Syntax error]"); } else { if ($runtime_error) { $conn = mysqli_connect(host, user, pw, db); $cur_time = date("Y-m-d H:i:s"); $output_a = mysqli_real_escape_string($conn, $exec_data['output']); $query = "INSERT INTO submissions (id, team, problem, time, subid, code, output, success, error, real_output) VALUES (NULL, '{$team}', '{$problem_number}','{$cur_time}','{$processname}','{$data}','{$output_a}', 'No', 'Runtime', '{$file_output_data}')"; mysqli_query($conn, $query); mysqli_close($conn); return array("success" => "false", "error" => "Your program encountered an error while running! Please check your program logic and resubmit. [Runtime error]"); } } } //something terrible occured return array("success" => "false", "error" => "Unknown error, something huge has gone wrong!"); }
<?php /*** * use to test the clasee redis_face.php */ require_once 'iredis.php'; function judge($status, $cmd) { if ($status == 0 || $status == true) { echo "<p class=\"lead\">"; echo $cmd . " success."; echo "<p/>"; } else { echo "<p class=\"lead\">"; echo $cmd . " failed."; echo "<p/>"; # var_dump($status); } } echo "<h1>下面为测试redis的php接口类iredis的各种命令.</h1>"; $rf = new iredis(); $status = $rf->set('lenovo', 'shanghai'); judge($status, "set"); $status = $rf->del('lenovo'); judge($status, "del"); $status = $rf->hset('go', 'shanghai', 'e2e2'); judge($status, "hset"); $status = $rf->delete('go'); judge($status, "delete");
<?php // 親のカード $parentCard = getLineDataSplitedBySpace(fgets(STDIN)); // 子の情報 $childrenCount = trim(fgets(STDIN)); for ($i = 0; $i < $childrenCount; $i++) { // 子のカード $childCard = getLineDataSplitedBySpace(fgets(STDIN)); judge($parentCard, $childCard); } // High and Lowの判定 function judge($parentCard, $childCard) { $result = "Low"; // 親の1枚目のほうが子の1枚目より // 親の1枚目と子の1枚目が同じとき、親の2枚目が子の2枚目より小さい if ($parentCard[0] > $childCard[0] || $parentCard[0] === $childCard[0] && $parentCard[1] < $childCard[1]) { $result = "High"; } echo $result . "\n"; } /** * 空白で区切られたデータを配列で返却する * */ function getLineDataSplitedBySpace($lineData) { $lineData = trim($lineData); $lineDatas = split(" ", $lineData); return $lineDatas;
$_SESSION['p1send'][$_SESSION['rond']] = $_POST['p1send']; $result = compare($_SESSION['p2num'], $_SESSION['p1send'][$_SESSION['rond']]); $_SESSION['p1corect'][$_SESSION['rond']] = $result[0]; $_SESSION['p1contain'][$_SESSION['rond']] = $result[1]; $_SESSION['p1bad'][$_SESSION['rond']] = $result[2]; $_SESSION['turn'] = "p2"; judge($_SESSION['rond']); } else { if ($_SESSION['turn'] == "p2" && isset($_POST['p2send'])) { $_SESSION['p2send'][$_SESSION['rond']] = $_POST['p2send']; $result = compare($_SESSION['p1num'], $_SESSION['p2send'][$_SESSION['rond']]); $_SESSION['p2corect'][$_SESSION['rond']] = $result[0]; $_SESSION['p2contain'][$_SESSION['rond']] = $result[1]; $_SESSION['p2bad'][$_SESSION['rond']] = $result[2]; $_SESSION['turn'] = "p1"; judge(roundLimit($_SESSION['rond'])); $_SESSION['rond']++; } } } ?> <h1>NumberGame</h1> <div class="p1"> <table border="1" class="battle"> <caption>Player1</caption> <tr> <th>Name</th> <td colspan="4"><?php echo $_SESSION['p1name']; ?> </td>