我在php中讀取一個txt文件。問題是我可以除了它的空間。我使用了explode()函數,但它不起作用。我嘗試了所有的方法來閱讀,但沒有對。php讀取空格的txt文件
$a = file_get_contents($file_url, FILE_USE_INCLUDE_PATH);
$a = explode(" ",$a);//When I call this, all of value are added to $a[0] as an array
$a = explode("\n",$a[0]); // I called this to explode "enter" but it doesn't work too
現在,在調用上面的代碼後,$ a [0]是「85」,$ a [1]是「94 16」。當我打電話給$ a [1] [0]時,它是「9」而不是「94」。
在TXT文件中的數據是一個三角形在1994年IOI問題:
85
94 16
15 63 72
55 78 89 105
77 24 56 93 17
...
這是我想用http://www.mediafire.com/?kjdjflvf0665q03
文件,這是我的代碼來解決問題三角形從txt文件此數據
$t = array();
$count = 0;
$l = strlen($a[0]);
$d = 0;//get the quantity of rows in txt file
while($l>0){
$d++;
$l = $l - $d;
}
$f = array();
$prevX = $prevY = $val = 0;
//add all of values to array $t[] as a type: $t[row][col]
for($i =0 ; $i<$d; $i++){
for($j=0; $j<=$i; $j++){
$t[$i][$j] = $a[0][$count++];
}
}
//start the beginning points: $f[row+1][col] = ($t[row+1][col]+MAX(f[row][col],f[row][col-1]),prevX, prevY, $t[row+1][col])
$f[0][0] = array($t[0][0],$prevX,$prevY, $t[0][0]);
$f[1][0] = array(($t[1][0]+$f[0][0][0]),0,0,$t[1][0]);
$f[1][1] = array(($t[1][1]+$f[0][0][0]),0,0,$t[1][1]);
$i=2;
while($i<$d){
for ($j=0; $j <= $i; $j++){
if(($j-1)<0){//check to except the value which not undefined, but may be not works exactly
$f[$i][$j] = array(($f[$i-1][$j][0]+$t[$i][$j]),$i-1,$j,$t[$i][$j]);
}
else {
if($j>($i-1)){//check to except the value which not undefined, but may be not works exactly
$f[$i][$j] = array(($f[$i-1][$j-1][0]+$t[$i][$j]),$i-1,$j-1,$t[$i][$j]);
}
else{
if($f[$i-1][$j][0]<$f[$i-1][$j-1][0]){
$f[$i][$j] = array(($f[$i-1][$j-1][0]+$t[$i][$j]),$i-1,$j-1,$t[$i][$j]);
}
else if($f[$i-1][$j][0]>$f[$i-1][$j-1][0]){
$f[$i][$j] = array(($f[$i-1][$j][0]+$t[$i][$j]),$i-1,$j,$t[$i][$j]);
}
}
}
}
$i++;
}
//print_r($f);
$result=0;
$x = $y = $finalR = 0;
for($j=0;$j<$d;$j++){
if($f[$d-1][$j][0]>$result){
$result = $f[$d-1][$j][0];
$x = $d-1;
$y = $j;
$finalR = $f[$d-1][$j][3];
}
}
while($x>0){
echo '(',$x,',',$y,')',$f[$x][$y][3],'<----';
$x = $f[$x][$y][1];
$y = $f[$x][$y][2];
}
echo '(0,0)', $f[0][0][3];
請包括我加入它,JohnP文件 – JohnP
的內容。請幫幫我。謝謝 – JoeNguyen
請,我需要幫助 – JoeNguyen