Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Runtime Error (Exit code 1) on "Ball in Berland". GoLang

Правка en1, от kadobot, 2021-02-08 19:00:40

I'm starting with Go, and decided to tackle this problem. I believe the code is correct, but for some reason, I'm getting different Exit Code's when running the tests. Can someone help me figuring out how to fix this?

Link to submission

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

type ii int
type oo int

var scanner = bufio.NewScanner(os.Stdin)
var cache = make(map[string]oo)

// SplitNums splits a string into a slice of integers
func SplitNums(s string) []ii {
	nums := strings.Split(strings.TrimSpace(s), " ")
	var result []ii
	for _, n := range nums {
		result = append(result, ParseInt(n))
	}
	return result
}

// ParseInt converts a string into an integer
func ParseInt(s string) ii {
	num, err := strconv.ParseInt(strings.TrimSpace(s), 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return ii(num)
}

// ReadInput reads the input and returns the text
func ReadInput() string {
	scanner.Scan()
	return scanner.Text()
}

func solve(qty, boys, girls []ii) oo {
	g := make(map[ii]oo)
	b := make(map[ii]oo)
	for i := ii(0); i < qty[2]; i++ {
		g[boys[i]]++
		b[girls[i]]++
	}

	var total oo
	for i := ii(0); i < qty[2]; i++ {
		total += ((oo(qty[2]) - 1) - (g[boys[i]] - 1) - (b[girls[i]] - 1))
	}
	return total / 2
}

func main() {
	input := ReadInput()
	test_cases := ParseInt(input)

	for i := ii(0); i < test_cases; i++ {
		qty := SplitNums(ReadInput())
		boys := SplitNums(ReadInput())
		girls := SplitNums(ReadInput())
		fmt.Println(solve(qty, boys, girls))
	}
}
Теги golang, runtime error, exit code 1

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский kadobot 2021-02-08 19:00:40 1716 Initial revision (published)