Skip to content

Instantly share code, notes, and snippets.

@Horaddrim
Last active August 17, 2017 20:59
Show Gist options
  • Save Horaddrim/cdca0a72d5b049640f46817d5992a7f1 to your computer and use it in GitHub Desktop.
Save Horaddrim/cdca0a72d5b049640f46817d5992a7f1 to your computer and use it in GitHub Desktop.
A simple implementation for a future project >:D
package main
import (
"fmt"
"os"
"strings"
)
func colherEstatisticas(palavras []string) map[string]int {
estatisticas := make(map[string]int)
for _,palavra := range palavras {
inicial := strings.ToUpper(string(palavra))
contador, encontrado := estatisticas[inicial]
if encontrado {
estatisticas[inicial] = contador + 1
} else {
estatisticas[inicial] = 1
}
}
return estatisticas
}
func imprimir(estatisticas map[string]int) {
fmt.Println("Contagem das palavras iniciadas com cada letra: ")
for inicial,contador := range estatisticas {
fmt.Printf("%s = %d\n", inicial, contador)
}
}
func main(){
palavras := os.Args[1:]
estatisticas := colherEstatisticas(palavras)
imprimir(estatisticas)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment