Tag problem

Report a typo

The algorithm in this task takes a string as input. It would contain a word inside HTML tags. Your task is to print indexes, at which the tags begin and end. Please print the answer in two lines: first the indexes for the opening tag, and then, on the second line, the indexes for the closing tag. Each line should contain two numbers, separated by whitespace: the index where the tag begins, and the index where it ends.

Sample Input 1:

<p>Hi!</p>

Sample Output 1:

0 2
6 9
Write a program in Go
package main

import (
"fmt"
"strings"
)

func main() {
var source string

fmt.Scan(&source)

openingTagStart := strings.Index(source, "<")
openingTagEnd := strings.Index(?, ">")

closingTagStart := strings.LastIndex(source, ?)
closingTagEnd := strings.LastIndex(?, ?)

fmt.Printf("%d %d\n", openingTagStart, openingTagEnd)
fmt.Printf("%d %d\n", ?, ?)
}
___

Create a free account to access the full topic