Heads or tails

Report a typo

You will get a string with random lowercase letters without spaces. The string includes two control words: heads and tails. The string can consist of one of them, both of them, or none.

You need to create two regexps to match heads and tails, and then print the following messages if there is a match:

  • "heads" — if the string contains heads;
  • "tails" — if the string contains tails;
  • "both" — if the string contains both control words;
  • "none" — if the string doesn't contain any of the control words.

Sample Input 1:

okultailsfdheadsflwtntsx

Sample Output 1:

both
Write a program in Go
package main

import (
"fmt"
"regexp"
)

func main() {
var source string
fmt.Scan(&source)

reHeads := regexp.MustCompile(`?`)
reTails := regexp.?(?)

heads := reHeads.?(?)
tails := reTails.?(?)

switch {
case heads && tails:
?
case heads:
?
case tails:
?
default:
fmt.Println("none")
}
}
___

Create a free account to access the full topic