From 86591f1c285a3fedde8fc6c87aa70908208c7ede Mon Sep 17 00:00:00 2001 From: JACKYMYPERSON Date: Sat, 6 Sep 2025 21:25:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95main?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 测试/main.go | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 测试/main.go diff --git a/测试/main.go b/测试/main.go new file mode 100644 index 0000000..13e8006 --- /dev/null +++ b/测试/main.go @@ -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) + +}