I'm new to go and can't figure out how to do this task:
Write a program that, in the first line, reads from the standard input the number of consecutive digits in the range [1; 9], which will then be loaded into the array. Then prints the number of repeated instances of the specified array value to the standard output.
Input:
7
1 1 2 2 1 3 5
Output:
1: 3
2: 2
3: 1
5: 1
I have completed this task halfway, but I can't figure out how to do duplicate tracking via map
func main() {
var numbers int
fmt.Println("num: ")
fmt.Scan(&numbers)
var numArr int
var i = 1
arr := make([]int, 0)
if numbers <= 9 {
for ; i <= numbers; i++ {
fmt.Println("numArr: ")
fmt.Scan(&numArr)
if numArr < 9 {
arr = append(arr, numArr)
} else {
fmt.Println("sorry write the number up to 9")
break
}
}
} else {
fmt.Println("Max Numbers = 9")
}
fmt.Println(arr)
m := make(map[int]int)
for key, v := range arr {
}