增加测试main
This commit is contained in:
91
测试/main.go
Normal file
91
测试/main.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
scanner.Scan()
|
||||
lineText := scanner.Text()
|
||||
first := strings.Fields(lineText)
|
||||
res := 0
|
||||
var firstlist []int
|
||||
for _, v := range first {
|
||||
num, _ := strconv.Atoi(v)
|
||||
firstlist = append(firstlist, num)
|
||||
}
|
||||
n, p, q := firstlist[0], firstlist[1], firstlist[2]
|
||||
hash := make(map[string]int)
|
||||
for i := 0; i < n; i++ {
|
||||
scanner.Scan()
|
||||
lineText1 := scanner.Text()
|
||||
second := strings.Fields(lineText1)
|
||||
a, b, c := second[0], second[1], second[2]
|
||||
d := a + b + c
|
||||
hash[d]++
|
||||
}
|
||||
//fmt.Println(hash)
|
||||
for k, _ := range hash {
|
||||
//fmt.Println("当前k:", k)
|
||||
leftorright := string(k[0])
|
||||
red := string(k[len(k)-1])
|
||||
body := string(k[1 : len(k)-1])
|
||||
if leftorright == string("1") {
|
||||
target := string("0" + body + red)
|
||||
//fmt.Println("查询:", target)
|
||||
if value, ok := hash[target]; ok {
|
||||
if value > 0 {
|
||||
res += p
|
||||
hash[target]--
|
||||
hash[k]--
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if red == string("1") {
|
||||
target = string("0" + body + "2")
|
||||
} else {
|
||||
target = string("0" + body + "1")
|
||||
}
|
||||
if value, ok := hash[target]; ok {
|
||||
if value > 0 {
|
||||
res += q
|
||||
hash[target]--
|
||||
hash[k]--
|
||||
}
|
||||
}
|
||||
//fmt.Println("当前hash:", hash)
|
||||
} else {
|
||||
target := string("1" + body + red)
|
||||
//fmt.Println("查询1:", target)
|
||||
if value, ok := hash[target]; ok {
|
||||
if value > 0 {
|
||||
res += p
|
||||
hash[target]--
|
||||
hash[k]--
|
||||
continue
|
||||
}
|
||||
}
|
||||
if red == string("1") {
|
||||
target = string("1" + body + "2")
|
||||
} else {
|
||||
target = string("1" + body + "1")
|
||||
}
|
||||
if value, ok := hash[target]; ok {
|
||||
if value > 0 {
|
||||
res += q
|
||||
hash[target]--
|
||||
hash[k]--
|
||||
}
|
||||
}
|
||||
//fmt.Println("当前hash:", hash)
|
||||
}
|
||||
}
|
||||
fmt.Println(res)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user