自己写的采集lintcode.com上面的试题

public function index(){
 				set_time_limit(0);


				$handle = array(
					"http://www.lintcode.com/zh-cn/problem/merge-intervals",
					"http://www.lintcode.com/zh-cn/problem/count-1-in-binary",
					"http://www.lintcode.com/zh-cn/problem/fibonacci",
					"http://www.lintcode.com/zh-cn/problem/delete-node-in-the-middle-of-singly-linked-list",
					"http://www.lintcode.com/zh-cn/problem/subtree",
					"http://www.lintcode.com/zh-cn/problem/coins-in-a-line",
					"http://www.lintcode.com/zh-cn/problem/best-time-to-buy-and-sell-stock-iv",
					"http://www.lintcode.com/zh-cn/problem/house-robber",
					"http://www.lintcode.com/zh-cn/problem/candy",
					"http://www.lintcode.com/zh-cn/problem/reverse-integer",
					"http://www.lintcode.com/zh-cn/problem/gray-code",
					"http://www.lintcode.com/zh-cn/problem/divide-two-integers",
					"http://www.lintcode.com/zh-cn/problem/plus-one",
					"http://www.lintcode.com/zh-cn/problem/add-binary",
					"http://www.lintcode.com/zh-cn/problem/assignment-operator-overloading-c-only",
					"http://www.lintcode.com/zh-cn/problem/print-numbers-by-recursion",
					"http://www.lintcode.com/zh-cn/problem/container-with-most-water",
					"http://www.lintcode.com/zh-cn/problem/longest-substring-without-repeating-characters",
					"http://www.lintcode.com/zh-cn/problem/the-smallest-difference",
					"http://www.lintcode.com/zh-cn/problem/count-of-smaller-number-before-itself",
					"http://www.lintcode.com/zh-cn/problem/valid-sudoku",
					"http://www.lintcode.com/zh-cn/problem/expression-tree-build",
					"http://www.lintcode.com/zh-cn/problem/convert-expression-to-reverse-polish-notation",
					"http://www.lintcode.com/zh-cn/problem/building-outline",
					"http://www.lintcode.com/zh-cn/problem/count-of-smaller-number",
					"http://www.lintcode.com/zh-cn/problem/permutation-sequence",
					"http://www.lintcode.com/zh-cn/problem/expression-evaluation",
					"http://www.lintcode.com/zh-cn/problem/intersection-of-two-linked-lists",
					"http://www.lintcode.com/zh-cn/problem/spiral-matrix",
					"http://www.lintcode.com/zh-cn/problem/trapping-rain-water",
					"http://www.lintcode.com/zh-cn/problem/sliding-window-maximum",
					"http://www.lintcode.com/zh-cn/problem/first-missing-positive",
					"http://www.lintcode.com/zh-cn/problem/interval-sum",
					"http://www.lintcode.com/zh-cn/problem/interval-minimum-number",
					"http://www.lintcode.com/zh-cn/problem/singleton",
					"http://www.lintcode.com/zh-cn/problem/segment-tree-modify",
					"http://www.lintcode.com/zh-cn/problem/segment-tree-query",
					"http://www.lintcode.com/zh-cn/problem/permutation-index",
					"http://www.lintcode.com/zh-cn/problem/wildcard-matching",
					"http://www.lintcode.com/zh-cn/problem/maximum-product-subarray",
					"http://www.lintcode.com/zh-cn/problem/gas-station",
					"http://www.lintcode.com/zh-cn/problem/matrix-zigzag-traversal",
					"http://www.lintcode.com/zh-cn/problem/largest-number",
					"http://www.lintcode.com/zh-cn/problem/wood-cut",
					"http://www.lintcode.com/zh-cn/problem/delete-digits"
				);
				


				
			foreach($handle as $h){
				 
				$data = array();


 				$content = file_get_contents($h);
			 	/*去除掉所有的空格*/		
			 	$content = str_replace(array("\r", "\n"," "), "", $content);	


			 
			 	/*匹配了标题*/
			 	$reg = '#<spanclass="m-t-sm">(.*?)</span>#';
			 	preg_match($reg,$content,$arr);
			 	$data['title'] = $arr[1];




			 	/*匹配了简介*/
			 	$reg = '#</label></div><p>(.*?)</p></div>#';
				preg_match($reg,$content,$arr);
				$data['des'] = $arr[1];
			  	


				/*匹配了时间限制*/
				$reg = '#Countdownlimitvariesduetodifficulty"><span>(.*?)</span></div>#';
				preg_match($reg,$content,$arr);
				$data['limit_time'] = (int)$arr[1];
				$data['mem_limit'] = 3000;




			 	/*匹配标签*/
			 	$reg = '#<aclass="labelbg-success"href=(.*?)>(.*?)</a>#';
			 	preg_match_all($reg,$content,$arr);
			 	$data['tag_list'] = implode(',',$arr[2]);




			 	/*******************获取代码*******************/


			 	/*获取id*/
			 	$reg = '#name="problem_id"value="(.*?)"id="problem-id">#';
			 	preg_match($reg,$content,$id);




			 	/*获取实现的语言*/	 		
			 	$reg = '#<footerclass="footerb-t">(.*?)</select>#';
			 	preg_match($reg,$content,$lang);


			 	$reg = '#<optionvalue="(.*?)">(.*?)</option>#'; 
			 	preg_match_all($reg,$lang[1],$arr);


			  	


			 	/*获取实际的代码*/
			 	for($i=0;$i<count($arr[2]);$i++){


				 	$code = file_get_contents('http://www.lintcode.com/zh-cn/problem/api/code/?problem_id='.$id[1].'&language='.urlencode($arr[2][$i]));


				 	
				 	$code_arr = json_decode($code,true);




				 	$data['init_code'][] = array("file_name"=>$arr[2][$i],"code"=>$code_arr['code']);
					 
			 	}
			 	$data['init_code'] = json_encode($data['init_code']);


			 	$data['type'] = "编程题";		






			 	M('challenge_topic')->add($data);


			}


			echo "success";


	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值