Пример #1
0
 public function HDOJ_Problem($id = 1000)
 {
     require_once dirname(__FILE__) . "/HTMLParser.php";
     $html = new HTMLParser("http://acm.hdu.edu.cn/showproblem.php?pid=" . $id);
     $html->optHTMLLink();
     //Just a hack for OS X
     $sub_start = 0;
     $pro_info = array('title' => substr($html->innerHTML("<h1 style='color:#1A5CC8'>", '</h1>'), $sub_start));
     $pro_info['time'] = substr($html->innerHTML('<span style=\'font-family:Arial;font-size:12px;font-weight:bold;color:green\'>Time Limit: ', ' MS (Java/Others)'), $sub_start);
     $pro_info['memory'] = substr($html->innerHTML('MS (Java/Others)&nbsp;&nbsp;&nbsp;&nbsp;Memory Limit: ', ' K (Java/Others)<br>'), $sub_start);
     $pro_info['submissions'] = substr($html->innerHTML('Total Submission(s): ', '&nbsp;&nbsp;&nbsp;&nbsp;Accepted'), $sub_start);
     $pro_info['accepted'] = substr($html->innerHTML('Accepted Submission(s): ', '<br></span></b></font>'), $sub_start);
     $pro_info['description'] = substr($html->innerHTML('<div class=panel_title align=left>Problem Description</div> <div class=panel_content>', '</div><div class=panel_bottom>'), $sub_start);
     $pro_info['input'] = substr($html->innerHTML('<div class=panel_title align=left>Input</div> <div class=panel_content>', '</div><div class=panel_bottom>'), $sub_start);
     $pro_info['output'] = substr($html->innerHTML('<div class=panel_title align=left>Output</div> <div class=panel_content>', '</div><div class=panel_bottom>'), $sub_start);
     $pro_info['sample_input'] = substr($html->innerHTML('<div class=panel_title align=left>Sample Input</div><div class=panel_content><pre>', '</pre>'), $sub_start);
     $pro_info['sample_output'] = substr($html->innerHTML('<div class=panel_title align=left>Sample Output</div><div class=panel_content><pre>', '</pre>'), $sub_start);
     $pro_info['hint'] = "N/A";
     $pro_info['source'] = substr($html->innerHTML('<div class=panel_title align=left>Author</div> <div class=panel_content>', '</div><div class=panel_bottom>'), $sub_start);
     foreach ($pro_info as $k => $v) {
         $pro_info[$k] = iconv('GB2312', 'UTF-8', $v);
     }
     $this->pro_info = $pro_info;
 }
Пример #2
0
 public function getIdFromSource($RunID)
 {
     //Infomation
     $cookie_file = tempnam("./cookie", "cookie");
     $login_url = "http://poj.org/login";
     $post_fields = "user_id1=" . $this->user . "&password1=" . $this->pass . "&url=/";
     //Login
     $curl = curl_init($login_url);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields);
     $this->data = curl_exec($curl);
     //Get Source
     $curl = curl_init("http://poj.org/showsource?solution_id=" . $RunID);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file);
     $src = curl_exec($curl);
     @unlink($cookie_file);
     $th = new HTMLParser();
     $th->loadHTML($src);
     return $th->innerHTML('//&lt;ID&gt;', '&lt;/ID&gt;');
 }
Пример #3
0
 public function getIdFromSource($RunID)
 {
     //Get Source
     $curl = curl_init("http://acm.hdu.edu.cn/viewcode.php?rid=" . $RunID);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_COOKIEFILE, $this->cookie_file);
     $src = curl_exec($curl);
     $th = new HTMLParser();
     $th->loadHTML($src);
     return $th->innerHTML('//&lt;ID&gt;', '&lt;/ID&gt;');
 }
Пример #4
0
 public function POJ_Problem($id = 1000)
 {
     require_once dirname(__FILE__) . "/HTMLParser.php";
     $html = new HTMLParser("http://poj.org/problem?id=" . $id);
     $html->optHTMLLink();
     $pro_info = array('title' => $html->innerHTML('<div class="ptt" lang="en-US">', '</div>'));
     $prefix = $html->startString('<div class="ptt" lang="en-US">' . $pro_info['title']);
     $pro_info['time'] = intval($html->innerHTML('<div class="plm"><table align="center"><tr><td><b>Time Limit:</b> ', 'MS</td>', $prefix));
     $pro_info['memory'] = intval($html->innerHTML('MS</td><td width="10px"></td><td><b>Memory Limit:</b> ', 'K</td>'));
     $pro_info['submissions'] = intval($html->innerHTML('Total Submissions:</b> ', '</td>'));
     $pro_info['accepted'] = intval($html->innerHTML('</td><td><b>Accepted:</b> ', '</td>'));
     $pro_info['description'] = $html->innerHTML('<p class="pst">Description</p><div class="ptx" lang="en-US">', '</div>');
     $pro_info['input'] = $html->innerHTML('<p class="pst">Input</p><div class="ptx" lang="en-US">', '</div>');
     $pro_info['output'] = $html->innerHTML('<p class="pst">Output</p><div class="ptx" lang="en-US">', '</div>');
     $pro_info['sample_input'] = $html->innerHTML('<p class="pst">Sample Input</p><pre class="sio">', '</pre>');
     $pro_info['sample_output'] = $html->innerHTML('<p class="pst">Sample Output</p><pre class="sio">', '</pre>');
     $pro_info['hint'] = $html->innerHTML('<p class="pst">Hint</p><div class="ptx" lang="en-US">', '</div><p class="pst">Source</p>');
     $pro_info['source'] = $html->innerHTML('<p class="pst">Source</p><div class="ptx" lang="en-US">', '</div>');
     $this->pro_info = $pro_info;
 }
Пример #5
0
 public function getIdFromSource($RunID)
 {
     $cookie_file = tempnam("./cookie", "cookie");
     $this->cookie_file = $cookie_file;
     $login_url = "http://acm.hdu.edu.cn/userloginex.php?action=login";
     $post_fields = "username="******"&userpass="******"&login=Sign In";
     //Login
     $curl = curl_init($login_url);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields);
     $this->data = curl_exec($curl);
     //Get Source
     $curl = curl_init("http://acm.hdu.edu.cn/viewcode.php?rid=" . $RunID);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_COOKIEFILE, $this->cookie_file);
     $src = curl_exec($curl);
     $th = new HTMLParser();
     $th->loadHTML($src);
     return $th->innerHTML('//&lt;ID&gt;', '&lt;/ID&gt;');
 }