|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
首先 我们 需要 判断 手中拿到的牌型, 比如你有多少个9,多少个10 这时候 我们就需要对 手中的牌进行聚合
假设 A, B ,C ,D 分别代表四个花色,Q66代表 小王,K99 代表大王
你现在拿到的牌型如下 "B1", "C4", "A1", "B7", "C8", "C7", "C10", "K99", "B13", "D13", "A2", "B6", "D8", "A3", "D12", "D10"
go语言逻辑处理如下:
package main
import (
"fmt"
"strconv"
"strings"
)
func Rm_duplicateString(list []string) []string {
var x []string = []string{}
for _, i := range list {
if len(x) == 0 {
x = append(x, i)
} else {
for k, v := range x {
if i == v {
break
}
if k == len(x)-1 {
x = append(x, i)
}
}
}
}
return x
}
func Rm_duplicateInt(list []int) []int {
var x []int = []int{}
for _, i := range list {
if len(x) == 0 {
x = append(x, i)
} else {
for k, v := range x {
if i == v {
break
}
if k == len(x)-1 {
x = append(x, i)
}
}
}
}
return x
}
func aggregationlist(e []string) (aggregation []map[int]int) {
var cardstring []string = []string{}
var cardintsort []int = []int{}
var cardint []int = []int{}
for _, v := range e {
s := strings.Split(v, "")
if len(s[1:]) == 1 {
cardstring = append(cardstring, s[1])
} else if len(s[1:]) > 1 {
cardstring = append(cardstring, strings.Join(s[1:], ""))
}
}
for _, k := range cardstring {
l, _ := strconv.Atoi(k)
cardint = append(cardint, l)
}
cardintsort = Rm_duplicateInt(cardint)
for _, o := range cardintsort {
count := 0
for _, q := range cardint {
if q == o {
count = count + 1
}
}
//k := []int{o, count}
k := make(map[int]int)
k[o] = count
aggregation = append(aggregation, k)
}
return aggregation
}
func main() {
a := []string{"B1", "C4", "A1", "B7", "C8", "C7", "C10", "K99", "B13", "D13", "A2", "B6", "D8", "A3", "D12", "D10"}
fmt.Println(aggregationlist(a))
}
*************************************************************************************************
GoSublime r17.11.14-1 9o: type `help` for help and command documentation
[ `go run 10.go` | done: 8.832s ]
[map[1:2] map[4:1] map[7:2] map[8:2] map[10:2] map[99:1] map[13:2] map[2:1] map[6:1] map[3:1] map[12:1]]
[ F:/mygo/ ] # |
|