package main import "fmt" //func letterCombinations(digits string) []string { // //} func main() { //生成26个字母 var s []byte for i := 97; i < 97+26; i++ { s = append(s, byte(i)) } fmt.Printf("%c ", s) //字母和数字对应 //2-->abc //3-->def //7-->pqrs //8-->tuv //9-->wxyz /* 输入:"23" 输出:["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]. */ var m = make(map[int][]byte) var arr []byte flag := 2 for i := 0; i < len(s); i++ { arr = append(arr, byte(s[i])) //fmt.Printf("arr:%c ", arr) //如果长度大于3,存到map中 if len(arr) == 3 { m[flag] = arr //清空arr arr = []byte{} flag += 1 //fmt.Println("m->",m) } else { continue } } fmt.Println("m-->", m) //m--> map[2:[97 98 99] 3:[100 101 102] 4:[103 104 105] 5:[106 107 108] 6:[109 110 111] 7:[112 113 114] 8:[115 116 117] 9:[118 119 120]] m[7] = []byte{112, 113, 114, 115} m[8] = []byte{116, 117, 118} m[9] = []byte{119, 120, 121, 122} fmt.Println("m--->", m) //m---> map[2:[97 98 99] 3:[100 101 102] 4:[103 104 105] 5:[106 107 108] 6:[109 110 111] 7:[112 113 114 115] 8:[116 117 118] 9:[119 120 122 123]] var x, y int fmt.Scanln(&x, &y) map_x := m[x] map_y := m[y] //fmt.Println(map_x, map_y) var slice []string for i := 0; i < len(map_x); i++ { for j := 0; j < len(map_y); j++ { sum := string(map_x[i]) + string(map_y[j]) //fmt.Println(sum) slice = append(slice, sum) } } fmt.Println(slice) } /* 输入7和9 7 9 输出 [pw px py pz qw qx qy qz rw rx ry rz sw sx sy sz] */