// NewUserCase generates a test case from user input
NewUserCase generates a test case from user input
// NewUserCase generates a test case from user input
func NewUserCase(scanner *bufio.Scanner) int {
	ws = nil
	vs = nil
	fmt.Println("Weights of the items (integers):")
	scanner.Scan()
	for _, s := range strings.Fields(scanner.Text()) {
		n, err := strconv.Atoi(s)
		if err != nil {
			log.Fatalf("%s is not an integer number", s)
		}
		if n < 1 {
			log.Fatalf("weight cannot be negative: %s", s)
		}
		ws = append(ws, n)
	}
	fmt.Println("Values of the items (integers):")
	scanner.Scan()
	for _, s := range strings.Fields(scanner.Text()) {
		n, err := strconv.Atoi(s)
		if err != nil {
			log.Fatalf("%s is not an integer number", s)
		}
		vs = append(vs, n)
	}
	if len(ws) != len(vs) {
		log.Fatal("Lengths of weights and values do not match.")
	}
	fmt.Println("Weight capacity of the knapsack (integer):")
	scanner.Scan()
	s := scanner.Text()
	capacity, err := strconv.Atoi(s)
	if err != nil {
		log.Fatalf("Input %s is not an integer number.", s)
	}
	if capacity < 1 {
		log.Fatalf("weight cannot be negative: %s", s)
	}
	return capacity
}
func NewUserCase ( scanner * bufio . Scanner ) int { ws = nil vs = nil fmt . Println ( " " ) scanner . Scan ( ) for _ , s := range strings . Fields ( scanner . Text ( ) ) { n , err := strconv . Atoi ( s ) if err != nil { log . Fatalf ( " " , s ) } if n < 1 { log . Fatalf ( " " , s ) } ws = append ( ws , n ) } fmt . Println ( " " ) scanner . Scan ( ) for _ , s := range strings . Fields ( scanner . Text ( ) ) { n , err := strconv . Atoi ( s ) if err != nil { log . Fatalf ( " " , s ) } vs = append ( vs , n ) } if len ( ws ) != len ( vs ) { log . Fatal ( " " ) } fmt . Println ( " " ) scanner . Scan ( ) s := scanner . Text ( ) capacity , err := strconv . Atoi ( s ) if err != nil { log . Fatalf ( " " , s ) } if capacity < 1 { log . Fatalf ( " " , s ) } return capacity }
NewUserCase generates a test case from user input
NewUserCase generates a test case from user input