Example #1
0
func main() {
	help := flag.Bool("help", false, "show this message")
	inFile := flag.String("in", "", "input filename (required)")
	outFile := flag.String("out", "", "output filename (stdout if omitted)")

	flag.Parse()

	if *help {
		flag.Usage()
		os.Exit(0)
	}

	if len(*inFile) == 0 {
		flag.Usage()
		os.Exit(0)
	}

	pr := codejam.NewProblem(*inFile, *outFile)

	numTestCases := pr.ReadInt()

	if numTestCases < 1 {
		panic(fmt.Errorf("no testcases available"))
	}

	for testIndex := 1; testIndex <= numTestCases; testIndex++ {
		d := parse(pr, testIndex)
		solve(pr, d)
	}

	pr.Close()
}
Example #2
0
func main() {
	help := flag.Bool("help", false, "show this message")
	inFile := flag.String("in", "", "input filename (required)")
	outFile := flag.String("out", "", "output filename (stdout if omitted)")

	flag.Parse()

	if *help {
		flag.Usage()
		os.Exit(0)
	}

	if len(*inFile) == 0 {
		flag.Usage()
		os.Exit(0)
	}

	pr := codejam.NewProblem(*inFile, *outFile)

	ldn := pr.ReadInts(nil)
	if len(ldn) != 3 {
		panic(fmt.Errorf("invalid input"))
	}

	wordSize := ldn[0]
	dictSize := ldn[1]
	numTestCases := ldn[2]

	if numTestCases < 1 {
		panic(fmt.Errorf("no testcases available"))
	}

	root := new(trie)
	for i := 0; i < dictSize; i++ {
		root.insert([]byte(pr.ReadString()))
	}

	for testIndex := 1; testIndex <= numTestCases; testIndex++ {
		solve(pr, testIndex, pr.ReadString(), root, wordSize)
	}

	pr.Close()
}