|
http://www.hackerschool.org/HS_Boards/zboard.php?AllArticle=true&no=2970 [º¹»ç]
¾È³çÇϼ¼¿ä.
ÇÏ·çÀü ¿¡ Áú¹®¿Ã·Á³õ°í °±ÀÚ±â ÇÁ·Î±×·¥ÀÌ Á¦´ë·Î µ¹¾Æ°¡¼ ÇÇÇØ¸¸ÁØ ³ÑÀÔ´Ï´Ù ¤».
Á¦°¡ algorithms.php À» ¸¸µçÀÌÀ¯´Â hackthissite.org ¿¡ ÀÖ´Â programming mission 1À» Çϱâ À§Çؼ ¿´´Âµ¥¿ä.
¸·»ó ÇÏ·Á´Ï ¾ÈµÅ³×¿ä. (´Ù¸¥ ¾ð¾î·Î ¸¸µé¼ö´Â ÀÖÁö¸¸ Áö±ÝÀº php °øºÎÁßÀÌ¿©¼ ²À php ·Î ¸¸µé°í ½Í¾î¿ä ^0^ )
ÀÌÆ²µ¿¾È °í·Á ºÃ´Âµ¥ ¾ÈµÅ³×¿ä ¤Ð¤Ð.
¹Ì¼Ç ¼³¸í = Á¦°øÇÑ txt ÆÄÀÏ¿¡´Â 2000 ¿©°³ÀÇ ´Ü¾î°¡ Àִµ¥¿ä. ¹Ì¼ÇÀ» ½ÃÀÛÇÏ¸é ±×Áß 10°³ÀÇ ´Ü¾î¸¦ ¹«ÀÛÀ§·Î ¼±ÅÃÇÏ¿©¼
´Ü¾î¼øÀ» ¼¯¾î ¹ö¸³´Ï´Ù. ÆÄÀÏÀ» ÀÌ¿ëÇØ¼ original ´Ü¾î¸¦ ã¾Æ¾ß µÅ´Â°ÅÁÒ [Çѱ¹¸»ÀÌ ¼Åõ·¯¼ Àß ¼³¸íÀÌ µÆ´ÂÁö ¸ð¸£°Ú³×¿ä]
index.php ÄÚµå
<?php
require_once('algorithms.php');
/* Getting the txt file and putting it in to array $word_bank*/
if(isset($_POST['submit'])){
$text_file = $_FILES['text_file']['name'];
$word_bank = array();
/* Get the file & Make $word_bank array */
if(!empty($text_file)){
$file_tmp_name = $_FILES['text_file']['tmp_name'];
$file = fopen($file_tmp_name, "r");
while(!feof($file))
array_push($word_bank, fgets($file));
fclose($file);
@unlink($file_tmp_name);
}
else{
echo '<p>Please choose your file.</p>';
exit();
}
/* Receive the words and put them in to array $word*/
$words = $_POST['words'];
$word = explode("\n",$words);
find_word($word, $word_bank);
exit();
}
?>
<!--Form that receives the randomly picked words and the text file-->
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype = "multipart/form-data">
<fieldset>
<legend>Programming Mission 1</legend>
<label for="words">Words:</label><br>
<textarea name="words" id="words" cols="30" rows="4"></textarea>
<br>
<label for="text_file">Choose the file</label>
<input type="file" name="text_file">
</fieldset>
<input type="submit" name="submit" value="Done">
</form>
algorithms.php ÆÄÀÏ ÄÚµå
<?php
function find_word($a, $b){
// $a = scrambled word
// $b = one getting compared to (from the original list)
for($i=0; $i<count($a); $i++){
for($ii=0; $ii<count($b); $ii++){
$a_split= str_split($a[$i]);
$b_split= str_split($b[$ii]);
sort($a_split);
sort($b_split);
$new_a = implode('',$a_split);
$new_b = implode('',$b_split);
if($new_a == $new_b){
echo $b[$ii].', ';
}
}
}
}
?> |
Hit : 4022 Date : 2011/04/27 09:01
|