Problem Solving with Go course

Reading InputQuiz: Reading Input

Problem Solving with Go

Display

Theme

Reading Input · Quiz

Quiz: Reading Input

Check what you know about reading and splitting input: os.Stdin, bufio.Scanner, Fields, Split, Cut, blocks and regexps. Answer every question below.

  1. Question 1 of 6The input is "a\nb\n" (ending with a newline). How long is the slice this code produces?
    lines := strings.Split(input, "\n")
    fmt.Println(len(lines))
  2. Question 2 of 6What does strings.Fields(" 7 x 300 ") return?
  3. Question 3 of 6The line "blue green tea: 2 x 9000" needs splitting into the item name and the rest. Which fits best?
  4. Question 4 of 6A program splits blocks with strings.Split(input, "\n\n"), but for a file from Windows it always gets a single block. Why?
  5. Question 5 of 6Why do the parsing functions in this course take an io.Reader or a string instead of reading os.Stdin themselves?
  6. Question 6 of 6Which regexp pattern matches "(54 min)" and captures the number?