Go笔试题目Go与PHP分别实现方法
生活随笔
收集整理的這篇文章主要介紹了
Go笔试题目Go与PHP分别实现方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?題目?
Go實現?
?
PHP實現?
?
?代碼
package mainimport "fmt"var table = [][]int{{2, 2, 2, 0, 0, 0}, {0, 1, 5, 0, 0, 1}, {2, 1, 3, 3, 0, 0}, {3, 1, 1, 0, 0, 0}, {0, 2, 1, 0, 0, 0}} var res = map[int][]int{} var count intfunc main() {x := 0y := 1value := table[x][y]fmt.Println("要匹配的位置", x, y)fmt.Println("要匹配的數字", value)fmt.Println("要匹配的切片", table)show := Same(value, table)fmt.Println("要展示的結果", show) }func Same(value int, table [][]int) map[int][]int {for i := 0; i < len(table); i++ {for j := 0; j < len(table[i]); j++ {if table[i][j] == value {temp := []int{i, j}count++res[count] = temp}}}return res } <?php$table = [[1, 1, 2, 4], [3, 4, 1, 2,], [4, 1, 3, 2]]; $res = []; $x = 0; $y = 1;$match = $table[$x][$y]; var_dump("match:" . $match);foreach ($table as $x => $v1) {foreach ($v1 as $y => $v2) {if ($v2 == $match) {$res[] = [$x, $y];}} }var_dump($res);總結
以上是生活随笔為你收集整理的Go笔试题目Go与PHP分别实现方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 5升是多少克(2 5升是多少斤)
- 下一篇: Go的channel与map是否并发安全